I'm exporting data from SqlLite using TSQLConnection with the following procedure:
Campos := TStringList.Create;
SQLiteConnection.Execute('SELECT * FROM tabela', nil, results);
if not results.IsEmpty then
begin
results.GetFieldNames(Campos);
XLApp1 := createoleobject('excel.application');
XLApp1.Workbooks.Add(xlWBatWorkSheet);
Sheet := XLApp1.Workbooks[1].WorkSheets[1];
linha := 1;
begin
pBar.Max := results.RecordCount;
for coluna := 0 to results.FieldCount - 1 do
Sheet.Cells[1, coluna + 1] := Campos[coluna];
while ( not results.Eof ) do
begin
linha := linha + 1;
for coluna := 0 to results.FieldCount - 1 do
Sheet.Cells[linha, coluna + 1] := results.FieldByName(campos[coluna]).AsString;
results.next;
pBar.Position := pBar.Position + 1;
Application.ProcessMessages;
end;
end;
);
It works ok. But it takes too much time to finish. 35 minutes to export a table with 40,000 records and 45 fields on i7 note with SSD.
So my question: is there a chance I could do a little faster?
Application.ProcessMessages. It does not magically speed things up as most people think - it actually slows things down. It should never be used.Sheettwice in a row. Don't you get a compiler hint "Value assigned to 'Sheet' never used"?