数据库格式为 paradox
查询结果显示在dbgrid
怎样将其保存为 excel 文件
供参考:
//输出到 Excel 文件
procedure OutputExcel(ExcelApplication: TExcelApplication;DataSet: TQuery;Flag: integer);
var
Sheet1 : OleVariant; // Excel文件中的一页
j : integer; //循环控制表量
FieldNum: integer; //字段个数
begin
Sheet1 := ExcelApplication.Workbooks[1].Sheets[1];
Sheet1.visible := true;
if Flag = 0 then
begin
FieldNum := DataSet.FieldCount -1;
end
else
begin
FieldNum := DataSet.FieldCount -3;
end;
for j := 0 to FieldNum do // 输出标题
begin
Sheet1.Cells[CellRow,CellCol + j] := + DataSet.Fields[j].DisplayLabel;
Sheet1.Cells[cellrow,CellCol + j].Font.Name := 宋体;
Sheet1.Cells[cellrow,CellCol + j].Font.Size := 12;
Sheet1.Cells[cellrow,CellCol + j].Font.Bold := True;
end;
DataSet.First;
while not DataSet.Eof do // 输出内容
begin
Inc(CellRow);
for j := 0 to FieldNum do
begin
Sheet1.Cells[Cellrow,CellCol+j].Font.Name := 宋体;
Sheet1.Cells[cellrow,CellCol+j].Font.Size := 9;
Sheet1.Cells[CellRow,CellCol+j] := + DataSet.Fields[j].AsString;
end;
DataSet.Next;
end;
end;
//关闭EXCEL
procedure CloseExcel(ExcelApplication : TExcelApplication);
begin
ExcelApplication.Quit;
ExcelApplication.Disconnect;
end;