用的QR控件吗? QR对不同型号打印机支持并不完善 WINDOWS中纸张要设置为自定义 有时候还可能要换打印机驱动作报表可以利用SERVER页的EXCEL系列控件,以下是一个从DBGRID中导出数据至EXCEL的代码 procedure dbgridtoexcel(dbgrid1 : tdbgrid ); var hei ,i :integer; ExcelApplication1:tExcelApplication; ExcelWorkbook1:tExcelWorkbook; ExcelWorksheet1:tExcelWorksheet; begin ExcelApplication1:=tExcelApplication.create(dbgrid1); ExcelWorkbook1:=tExcelWorkbook.create(dbgrid1); ExcelWorksheet1:=tExcelWorksheet.create(dbgrid1); ExcelApplication1.Connect; ExcelApplication1.Visible[0]:=True; ExcelApplication1.Workbooks.Add(extractfilepath(application.exename)+'text\book1.xlt',0); ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]); ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet); with dbgrid1.DataSource.DataSet do if active then begin first; hei:=1; i:=0; for i:=0 to fieldcount-1 do begin ExcelWorksheet1.Cells.Item[hei,i+1]:=Fields[i].displaylabel; end; hei:=2; while not(eof) do begin for i:=0 to fieldcount-1 do begin ExcelWorksheet1.Cells.Item[hei,i+1]:=Fields[i].asstring; end; next; inc(hei,1); end; end else showmessage('请先打开相对应的数据源.'); ExcelApplication1.Disconnect; ExcelApplication1.Quit; ExcelApplication1.free; ExcelWorkbook1.free; ExcelWorksheet1.free; end;
QR对不同型号打印机支持并不完善
WINDOWS中纸张要设置为自定义
有时候还可能要换打印机驱动作报表可以利用SERVER页的EXCEL系列控件,以下是一个从DBGRID中导出数据至EXCEL的代码
procedure dbgridtoexcel(dbgrid1 : tdbgrid );
var hei ,i :integer;
ExcelApplication1:tExcelApplication;
ExcelWorkbook1:tExcelWorkbook;
ExcelWorksheet1:tExcelWorksheet;
begin
ExcelApplication1:=tExcelApplication.create(dbgrid1);
ExcelWorkbook1:=tExcelWorkbook.create(dbgrid1);
ExcelWorksheet1:=tExcelWorksheet.create(dbgrid1);
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Workbooks.Add(extractfilepath(application.exename)+'text\book1.xlt',0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
with dbgrid1.DataSource.DataSet do
if active then
begin
first;
hei:=1;
i:=0;
for i:=0 to fieldcount-1 do
begin
ExcelWorksheet1.Cells.Item[hei,i+1]:=Fields[i].displaylabel;
end;
hei:=2;
while not(eof) do
begin
for i:=0 to fieldcount-1 do
begin
ExcelWorksheet1.Cells.Item[hei,i+1]:=Fields[i].asstring;
end;
next;
inc(hei,1);
end;
end
else
showmessage('请先打开相对应的数据源.');
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.free;
ExcelWorkbook1.free;
ExcelWorksheet1.free;
end;