怎样完成数据的导出?(0分)

  • 主题发起人 主题发起人 人海茫茫
  • 开始时间 开始时间

人海茫茫

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi中,怎样把dbf格式的文件导出成execl或者acsess格式的文件?
请各位高手请教! 最好具体一些,因为我是新手^-^********
 
导入Excel:
procedure WriteExcel(AdsData: TDataSet;title:string);
var
i, j: integer;
date: string;
begin
try
ExcelApplication1 := TExcelApplication.Create(Application);
ExcelWorksheet1 := TExcelWorksheet.Create(Application);
ExcelWorkbook1 := TExcelWorkbook.Create(Application);
ExcelApplication1.Connect;
except
Application.Messagebox('Excel 导出失败,请检查是否安装了Excel或注销系统后再运行','错误', MB_ICONERROR + mb_Ok);
Abort;
end;
try
ExcelApplication1.Workbooks.Add(EmptyParam, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
ExcelWorksheet1.Cells.item[1, 3] := Title;
ExcelWorksheet1.Cells.Item[1, 3].font.size := '14';
ExcelWorksheet1.Cells.item[1, 3].font.Bold := true;
AdsData.First;
for j := 0 to AdsData.Fields.Count - 1 do
begin
ExcelWorksheet1.Cells.item[3, j + 1] := AdsData.Fields[j].DisplayLabel;
ExcelWorksheet1.Cells.item[3, j + 1].font.size := '10';
ExcelWorksheet1.Cells.item[3, j + 1].font.Bold := true; //??
end;
for i := 4 to AdsData.RecordCount + 3 do
begin
for j := 0 to AdsData.Fields.Count - 1 do
begin
ExcelWorksheet1.Cells.item[i, j + 1]:=AdsData.Fields[j].Asstring;
ExcelWorksheet1.Cells.item[i, j + 1].font.size:='10';
//ExcelWorksheet1.Cells.item[i, j + 1].Alignment:='chaLeft';
end;
AdsData.Next;
end;
//ExcelWorksheet1.Columns.AutoFit;

ExcelApplication1.visible[0]:=true;
// ExcelApplication1.visible[0]:=true;
except
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
end;
end;
 
后退
顶部