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;
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;