通过Pascal语言生成Excel表格
// 生成新的sheet
WorkSheet := workbook.Sheets.Add;
// 获取sheet对象
WorkSheet := workbook.Sheets[2];
// 执行写数据程序
WriteData2;
案例-超发统计报表
//定义常量-列标题
const aryVle = ['DocRef', 'OrderNo', 'style', 'DocInfo', 'shortName', 'SendTo', 'ReqQty', 'BomQty', 'IssQty', 'QtyUnit', 'SysLMDate'];
//定义变量
var
workbook: TXLSWorkBook;
WorkSheet: IXLSWorkSheet;
i,r: Integer;
//定义 写数据
Procedure WriteData;
begin
//赋值 起始行为第3行
r := 3;
with WorkSheet.Cells, result do begin
First;
while not Eof Do begin
inc(r);
for i := 0 to length(aryVle) - 1 do begin
if FieldByName(aryVle[i]).DataType = ftInteger then begin
Item[r, i+1].Value := FieldByName(aryVle[i]).AsInteger;
end else if FieldByName(aryVle[i]).DataType = ftFloat then begin
Item[r, i+1].Value := FieldByName(aryVle[i]).AsFloat;
end else begin
Item[r, i+1].Value := FieldByName(aryVle[i]).AsString;
end;
end;
Next;
end;
end;
end;
// 执行
begin
workbook := TXLSWorkBook.Create;
workbook.Open('Report.xls');
WorkSheet := workbook.Sheets[1];
WriteData;
workbook.SaveAs('Report2.xlsx');
ClearXLSList;
end.
标签:begin,end,WorkSheet,Pascal,API,workbook,相关,FieldByName,aryVle From: https://www.cnblogs.com/loveDonkey/p/17396786.html