D
daemon143
Unregistered / Unconfirmed
GUEST, unregistred user!
{
********************数据转换模块**********************
Author:j
Date:2002-07-23
Discription:将数据集中的数据导入到EXCEL中去
******************************************************
}
library project2;
uses
SysUtils,
Classes;
{$R *.res}
procedure DataToExcel(var dataset:TDataset;var excelapplication:TExcelApplication;var excelworkbook;var TExcelworkbook;excelworksheet:TExcelWorksheet);
var
iRow:integer;
C:integer;
FNames:Tstrings;
I:integer;
begin
dataset.create;
{***取得数据集共有几列***}
C:=dataset.fieldcount;
try
{***取得数据集中的列名***}
FNames:=Tstringlist.Create;
dataset.getfieldnames(Fnames);
{***连接到EXCEL***}
excelapplication.Connect;
excelapplication.Visible[0]:=true;
excelworkbook.ConnectTo(excelapplication.Workbooks.Add(emptyparam,0));
excelworksheet.connectto(excelworkbook1.sheets[1] as _worksheet);
{***将列名写入EXCEL***}
I:=1;
while i<=C do
begin
excelworksheet.cells.item[1,I]:=fnames[I-1];
inc(i);
end;
{***将数据写入到EXCEL***}
iRow:=1;
I:=1;
dataset.first;
while I<=C do
begin
while not dataset.eof do
begin
excelworksheet.cells.item[irow+2,I]:=dataset.fieldbyname(FNames[irow-1]).asstring;
inc(irow);
dataset.next;
end;
inc(I);
end;
finally
FNames.free;
end;
exports
DataToExcel;
end.
********************数据转换模块**********************
Author:j
Date:2002-07-23
Discription:将数据集中的数据导入到EXCEL中去
******************************************************
}
library project2;
uses
SysUtils,
Classes;
{$R *.res}
procedure DataToExcel(var dataset:TDataset;var excelapplication:TExcelApplication;var excelworkbook;var TExcelworkbook;excelworksheet:TExcelWorksheet);
var
iRow:integer;
C:integer;
FNames:Tstrings;
I:integer;
begin
dataset.create;
{***取得数据集共有几列***}
C:=dataset.fieldcount;
try
{***取得数据集中的列名***}
FNames:=Tstringlist.Create;
dataset.getfieldnames(Fnames);
{***连接到EXCEL***}
excelapplication.Connect;
excelapplication.Visible[0]:=true;
excelworkbook.ConnectTo(excelapplication.Workbooks.Add(emptyparam,0));
excelworksheet.connectto(excelworkbook1.sheets[1] as _worksheet);
{***将列名写入EXCEL***}
I:=1;
while i<=C do
begin
excelworksheet.cells.item[1,I]:=fnames[I-1];
inc(i);
end;
{***将数据写入到EXCEL***}
iRow:=1;
I:=1;
dataset.first;
while I<=C do
begin
while not dataset.eof do
begin
excelworksheet.cells.item[irow+2,I]:=dataset.fieldbyname(FNames[irow-1]).asstring;
inc(irow);
dataset.next;
end;
inc(I);
end;
finally
FNames.free;
end;
exports
DataToExcel;
end.