建立listbox1为选择字段,listbox2为打印字段
在QuickReport1(为TQuickRep)上建立QuickReport
上有QRBand1(Title),QRBand2(Columeheader),QRBand3(Detail)
RXDbgrid为显示数据的DBGRID,打印宽度由COLUME.WIDTH决定
可在QRband2上下功夫,设计标题头。自动生成按选择打印列
... type
ReportCom=record
MyLabel:TQRLabel;
MyText:TQrdbtext;
end;
var
Form_TodayReport: TForm_TodayReport;
Myreport: array[0..29] of ReportCom;// 最多可打印30列
...
procedure TForm_MyReport.OfficeButton16Click(Sender: TObject);
var
i,k:byte;
j:integer;
begin
if ListBox2.items.Count=0 then begin
Application.MessageBox('请选择要打印的项目','提示信息',mb_ok+MB_ICONINFORMATION);
exit;
end;
QuickReport1.quickreport.DataSet:=Form_TodayReport.Rx_Sell;
QuickReport1.QuickReport.OnNeedData:=nil;//如有自定义数据事件放在此处
j:=0;
for i:=0 to ListBox2.items.Count-1 do begin
for k:=0 to RxDBGrid6.Columns.Count-1 do if RxDBGrid6.Columns[k].FieldName=ListBox2.Items[i] then break;
myreport[i].MyLabel:=TQRLabel.Create(QuickReport1.QuickReport);
myreport[i].MyLabel.Parent:=QuickReport1.QRBand5;
myreport[i].MyLabel.Caption:=ListBox2.Items[i];
myreport[i].MyLabel.AutoSize:=False;
myreport[i].MyLabel.Left:=j;
myreport[i].MyLabel.Width:=RxDBGrid6.Columns[k].Width;
myreport[i].MyText:=TQRDBText.Create(QuickReport1.QuickReport);
myreport[i].MyText.Parent:=QuickReport1.QRband6;
myreport[i].MyText.DataSet:=Rx_Sell;
myreport[i].MyText.DataField:=ListBox2.Items[i];
myreport[i].MyText.AutoSize:=false;
myreport[i].MyText.Left:=j;
myreport[i].MyText.Width:=RxDBGrid6.Columns[k].Width;
j:=j+myreport[i].MyLabel.Width+10;
end;
QuickReport1.QuickReport.Preview;
for i:=0 to ListBox2.items.Count-1 do begin
myreport[i].MyLabel.free;
myreport[i].MyText.free;
end;
end;
在QuickReport1(为TQuickRep)上建立QuickReport
上有QRBand1(Title),QRBand2(Columeheader),QRBand3(Detail)
RXDbgrid为显示数据的DBGRID,打印宽度由COLUME.WIDTH决定
可在QRband2上下功夫,设计标题头。自动生成按选择打印列
... type
ReportCom=record
MyLabel:TQRLabel;
MyText:TQrdbtext;
end;
var
Form_TodayReport: TForm_TodayReport;
Myreport: array[0..29] of ReportCom;// 最多可打印30列
...
procedure TForm_MyReport.OfficeButton16Click(Sender: TObject);
var
i,k:byte;
j:integer;
begin
if ListBox2.items.Count=0 then begin
Application.MessageBox('请选择要打印的项目','提示信息',mb_ok+MB_ICONINFORMATION);
exit;
end;
QuickReport1.quickreport.DataSet:=Form_TodayReport.Rx_Sell;
QuickReport1.QuickReport.OnNeedData:=nil;//如有自定义数据事件放在此处
j:=0;
for i:=0 to ListBox2.items.Count-1 do begin
for k:=0 to RxDBGrid6.Columns.Count-1 do if RxDBGrid6.Columns[k].FieldName=ListBox2.Items[i] then break;
myreport[i].MyLabel:=TQRLabel.Create(QuickReport1.QuickReport);
myreport[i].MyLabel.Parent:=QuickReport1.QRBand5;
myreport[i].MyLabel.Caption:=ListBox2.Items[i];
myreport[i].MyLabel.AutoSize:=False;
myreport[i].MyLabel.Left:=j;
myreport[i].MyLabel.Width:=RxDBGrid6.Columns[k].Width;
myreport[i].MyText:=TQRDBText.Create(QuickReport1.QuickReport);
myreport[i].MyText.Parent:=QuickReport1.QRband6;
myreport[i].MyText.DataSet:=Rx_Sell;
myreport[i].MyText.DataField:=ListBox2.Items[i];
myreport[i].MyText.AutoSize:=false;
myreport[i].MyText.Left:=j;
myreport[i].MyText.Width:=RxDBGrid6.Columns[k].Width;
j:=j+myreport[i].MyLabel.Width+10;
end;
QuickReport1.QuickReport.Preview;
for i:=0 to ListBox2.items.Count-1 do begin
myreport[i].MyLabel.free;
myreport[i].MyText.free;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货