Use OLE Operation Excel (Wangda Supplement)
Author: Wangda, as reproduced please ensure the integrity of this document, and to indicate the source. Welcome to C Builder Research, http://www.ccrun.com/doc/go.asp? Id = 543 I have also written the BCB to call Excel on 9CBS. The "OLE OLE EXCEL (C Builder Version)" is exactly the same. If we use 2K operating system, you can find that if you just use Excelapp.pr ("Quit"), the Excel thread is still so, if the application does not exit, the called Excel file cannot be opened with Excel under the shell. Therefore, my BCB calls Excel is this in the end, it is necessary to add a little job. It is to set all the Variant variables to unassigned. One of my small examples, newly created an Excel file, how many forms show (Sheet ), Then add a form and name TEST, then assign a value to the (1, 2) unit.
Finally, delete a sheet. =============================================== =========================================== h file definition macro #define opg olepropertyget # define ops olepropertyset # define OFN OLEFUNCTION # define OPR OleProcedure # define PR Procedure add variables: Variant Axl, Workbook, AxSheet, nms, bef, aft; cpp function void __fastcall TForm1 :: Button1Click (TObject * Sender) {// assign the contents of AnsiString s =; / "hello!" / File path and save name ANSISURENTDIR () "// Test.xls"; // Judgment the file exists if (fileExists (fileEname)) {// ask if it is deleted if (Messagedlg already exists, Delete? ", MTWARNING, TMSGDLGBUTTONS () << mbok << mbcancel, 0) == mrok) deletefile; Else {ShowMessage; Return;}} // Established Excel connection AXL = Variant: : CreateObject ("Excel.Application"); AXL.OPS ("Visible", False); Workbook = AXL.OPG ("Workbooks"); // Create a new Excel Workbook (File) Workbook.exec (Pr (PR) "Add")); workbook = axl.opg ("ActiveWorkbook"); // Shows the existing sheet number int count = Workbook.opg ("Sheets"). OPG ("count"); showMessage (IntestStr (count) "A table"); // Add a Sheet, named Testaft = Workbook.opg ("Sheets", count); Workbook.opg ("Sheets") .Opr ("add", bef.noparam (), AFT); AXSHEET = Workbook.opg ("Activesheet"); // RenameaxSheet.Ops ("Name", "TEST"); // Assignment to unit 1, 2 Axsheet.Opg ("cells") .Opg ("item", (variant) 1, (variant) 2) .ops ("