(Delphi) EXCEL's rapid import

zhaozj2021-02-17  50

// How can I improve the export speed of Excel?

Uses adodb, excel97, adoint;

function TForm1.ExportToExcel: Boolean; var xlApp, xlBook, xlSheet, xlQuery: Variant; adoConnection, adoRecordset: Variant; begin adoConnection: = CreateOleObject ( 'ADODB.Connection'); adoRecordset: = CreateOleObject ( 'ADODB.Recordset'); adoConnection .Open ( 'Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E: /Tree.mdb; Persist Security Info = False'); adoRecordset.CursorLocation: = adUseClient; adoRecordset.Open ( 'SELECT * FROM tree', Adoconnection, 1, 3);

Try xlapp: = createoleObject ('Excel.Application'); xlbook: = xlapp.workbooks.add; xlsheet: = xlbook.worksheets ['Sheet1']; xlapp.visible: = true;

// Import the query results into Excel data xlquery: = xlsheet.querytables.add (adorecordset, xlsheet.range ['a1']); // The key is this XLQuery.fieldNames: = true; xlquery.rownumbers: = false; xlquery .FillAdjacentFormulas: = False; xlQuery.PreserveFormatting: = True; xlQuery.RefreshOnFileOpen: = False; xlQuery.BackgroundQuery: = True; //xlQuery.RefreshStyle: = xlInsertDeleteCells; xlQuery.SavePassword: = True; xlQuery.SaveData: = True; XlQuery.adjustColumnWidth: = true; xlquery.refreshperiod: = 0; xlquery.preservecolumninfo: = true; xlquery.fieldnames: = true; xlquery.refresh;

Xlbook.saves ('d: /fromd.xls', xlnormal,' ',', false, false);

Finally if NOT VARISEMPTY (XLAP) THEN BEGIN XLAPP.DISPLAYALERTS: = false; xlapp.screenupdating: = true;

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

New Post(0)