Delphi and Excel (2)

xiaoxiao2021-03-06  73

Excel's macro /// sub setpageInfo (Byval RegdateStr as String)

DIM I, MAXROW AS INTEGER 'acquires maximum maxRow Range ("a1"). Select Activecell.Specialcells (XLlastcell) .Select Maxrow = Activecell.row' Gets Date-Date Row Range ("A1"). SELECT While (Range ("A" & CSTR (I)). Value <> "DATELINE") AND (i> = 1) 'IF Range ("a" & cstr (i)). Value = "change1" Then' ROWS CSTR (I) & ":" & CSTR (i)). RowHeight = 21 'end if i = i - 1 Wend' Write Date Range ("G" & CSTR (i)). Select activecell.formular1c1 = BuydateStr ' Delete a column column ("a: a"). Select Selection.delete Shift: = XLTOLEFT RANGE ("A1"). SELECT END SUB

Delphi /// Uses como.Bobj, Excel97;

function ToExcelReport (dxSourceList: TdxTreeList): boolean; var XLApp, workbook, sheet: Variant; I_Row, I_Father, I_Child, I, J: integer; begin result: = true; try if not VarIsEmpty (XLApp) then begin XLApp.displayAlerts: = FALSE; XLAPP.QUIT; END;

(1) {- Open Excel file ----} xlapp: = createoleObject ('excel.application'); xlapp.workbooks.add (a_filename); // a_filename: An existing file Workbook: = XLAPP. Workbooks [1]; Sheet: = Workbook.Worksheets [1]; xlapp.displayalerts: = false; xlapp.screenupdating: = true; (2) {--- Create a new Excel file ----} xlapp: = createoleObject 'Excel.Application');

//Xlapp.visible :=true; xlapp.workbooks.add (xlwbatworksheet); // new worksheet xlapp.workbooks [1] .worksheets [1] .name: = 'newWorksheet'; Workbook: = xlapp.workbooks [1] Sheet: = workbook.works [1]; xlapp.displayalerts: = false; xlapp.screenupdating: = true; i_father: = dxsourceList.count; i_row: = 1; for i: = 0 to i_father-1 do begin i_child: = DXSourceList.items [i] .count; sheet.cells [i_row, 1]: = dxsourceList.items [i] .strings [0]; i_row: = i_row 1; for j: = 0 to i_child-1 do begin Sheet.cells [i_row, 1]: = DXSourceList.items [i] .Items [j] .strings [0]; i_row: = i_row 1; end; end; // Run macro //XLAPP.Run ('Macroname ', params ...) //Workbook.save; //workbook.saveas (afilename, xlnormal,' '' ,'activeworkbook.saveas; xlapp.visible: = true; EXCEPT RESULT: = FALSE; END;

Procedure tform1.formclosequery (seroClose: boolean); begin if not varisempty (xlapp) The begin xlapp.displayalerts: = false; xlapp.quit; end; end;

转载请注明原文地址:https://www.9cbs.com/read-109141.html

New Post(0)