var
Form1: TForm1;
procedure ExcelConv(AQuery: TQuery);//엑셀변환 프로시져
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
with Query1 do begin
DatabaseName := 'DBDEMOS';
Close;
SQL.Clear;
SQL.Add('select * from Customer');
SQL.Add('order by CustNo');
Open; //엑셀로 변환할 데이타 오픈
end;
end;
procedure ExcelConv(AQuery: TQuery);
var
XL, XArr, XTitle: Variant;
i, j, k: Integer;
begin
with AQuery do begin
//타이틀 처리변수
XTitle := VarArrayCreate([1, FieldCount], VarVariant);
//데이타 처리변수
XArr := VarArrayCreate([1, FieldCount], VarVariant);
try
//엑셀을 실행
XL := CreateOLEObject('Excel.Application');
except
MessageDlg('Excel이 설치되어 있지 않습니다.',
MtWarning, [mbok], 0);
Exit;
end;
XL.WorkBooks.Add; //새로운 페이지 생성
XL.Visible := True;
i := 1;
k := 1;
while i <= FieldCount do begin
XTitle[i] := Fields[i-1].FieldName;
Inc(i);
end;
//타이틀처리
XL.Range['A1', CHR(64 + FieldCount) + '1'].Value := XTitle;
First;
while Not EOF do begin
j := 1;
while j <= FieldCount do begin
if Fields[j-1].DataType = ftString then
XArr[j] := '''' + Fields[j-1].Value
else
XArr[j] := Fields[j-1].Value;
Inc(j);
end;
//셀에 값을 넣는다.
XL.Range['A' + IntToStr(k+1),
CHR(64 + FieldCount) + IntToStr(k+1)].Value := XArr;
Next;
Inc(k);
end;
//셀 크기 조정
XL.Range['A1', CHR(64 + FieldCount) + IntToStr(k)].Select;
XL.Selection.Columns.AutoFit;
XL.Range['A1', 'A1'].Select;
First;
end;
end;
end.
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);
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;
여기에서 바로 CSV를 검색하시면 금방 답을 얻으실수가 있을 겁니다.
그럼 즐프하시고요..