^^
DBGrid(Query)의 내용을 Excel로 변환하는데 속도가 넘 느린것 같아요.
어찌 속도를 빠르게 할 방법은 없는건가요?
참고로 Query의 RecordCount는 기본적으로10,000개 정도 되고 FieldCount는 14개 입니다. 그러니 총 데이터를 엑세스하는 횟수는 10000 * 14 = 140,000번이네요. 컴터가 노트북인데요 터지기 일보직전이예요.
v := CreateOLEObject('Excel.Application');
v.workBooks.Add;
Query2.first;
for i := 1 to Query2.RecordCount do
begin
for j := 1 to DBGrid1.FieldCount do
begin
v.Cells[i+1,j].Value := Query2.Fields[j-1].AsString;
end;
Query2.Next;
end;
v.Visible := True;
다음은 엑셀이 않 깔려 있어두 엑셀 파일을 만드는 코드거든요.
예전에 제가 테스트했던 코드는 못 찾겠구요 이거로 함 테스트 해보시져.
참고 하시고 유용하게 사용하세요.
const
CXlsBof: array[0..5] of Word = ($809, 8, 00, $10, 0, 0);
CXlsEof: array[0..1] of Word = ($0A, 00);
CXlsLabel: array[0..5] of Word = ($204, 0, 0, 0, 0, 0);
CXlsNumber: array[0..4] of Word = ($203, 14, 0, 0, 0);
CXlsRk: array[0..4] of Word = ($27E, 10, 0, 0, 0);
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure XlsBeginStream(XlsStream: TStream; const BuildNumber: Word);
begin
CXlsBof[4] := BuildNumber;
XlsStream.WriteBuffer(CXlsBof, SizeOf(CXlsBof));
end;
procedure XlsEndStream(XlsStream: TStream);
begin
XlsStream.WriteBuffer(CXlsEof, SizeOf(CXlsEof));
end;
procedure XlsWriteCellRk(XlsStream: TStream; const ACol, ARow: Word; const AValue: Integer);
var
V: Integer;
begin
CXlsRk[2] := ARow;
CXlsRk[3] := ACol;
XlsStream.WriteBuffer(CXlsRk, SizeOf(CXlsRk));
V := (AValue shl 2) or 2;
XlsStream.WriteBuffer(V, 4);
end;
procedure XlsWriteCellNumber(XlsStream: TStream; const ACol, ARow: Word; const AValue: Double);
begin
CXlsNumber[2] := ARow;
CXlsNumber[3] := ACol;
XlsStream.WriteBuffer(CXlsNumber, SizeOf(CXlsNumber));
XlsStream.WriteBuffer(AValue, 8);
end;
procedure XlsWriteCellLabel(XlsStream: TStream; const ACol, ARow: Word; const AValue: string);
var
L: Word;
begin
L := Length(AValue);
CXlsLabel[1] := 8 + L;
CXlsLabel[2] := ARow;
CXlsLabel[3] := ACol;
CXlsLabel[5] := L;
XlsStream.WriteBuffer(CXlsLabel, SizeOf(CXlsLabel));
XlsStream.WriteBuffer(Pointer(AValue)^, L);
end;
procedure TForm1.Button1Click(Sender: TObject);
var FStream: TFileStream;
I, J: Integer;
begin
FStream := TFileStream.Create('c:e.xls', fmCreate);
try
XlsBeginStream(FStream, 0);
for I := 0 to 99 do
for J := 0 to 99 do
begin
XlsWriteCellNumber(FStream, I, J, 34.34);
// XlsWriteCellRk(FStream, I, J, 3434);
// XlsWriteCellLabel(FStream, I, J, Format('Cell: %d,%d', [I, J]));
end;
XlsEndStream(FStream);
finally
FStream.Free;
end;
end;