建立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-1do
begin
for k:=0 to RxDBGrid6.Columns.Count-1do
if RxDBGrid6.Columns[k].FieldName=ListBox2.Items then
break;
myreport.MyLabel:=TQRLabel.Create(QuickReport1.QuickReport);
myreport.MyLabel.Parent:=QuickReport1.QRBand5;
myreport.MyLabel.Caption:=ListBox2.Items;
myreport.MyLabel.AutoSize:=False;
myreport.MyLabel.Left:=j;
myreport.MyLabel.Width:=RxDBGrid6.Columns[k].Width;
myreport.MyText:=TQRDBText.Create(QuickReport1.QuickReport);
myreport.MyText.Parent:=QuickReport1.QRband6;
myreport.MyText.DataSet:=Rx_Sell;
myreport.MyText.DataField:=ListBox2.Items;
myreport.MyText.AutoSize:=false;
myreport.MyText.Left:=j;
myreport.MyText.Width:=RxDBGrid6.Columns[k].Width;
j:=j+myreport.MyLabel.Width+10;
end;
QuickReport1.QuickReport.Preview;
for i:=0 to ListBox2.items.Count-1do
begin
myreport.MyLabel.free;
myreport.MyText.free;
end;
end;
摘自我编的程序的一部分,可能少部分语句。SORRY!