最后的报表为:
表头标题
物料名称 料1 料2 . . . 料5
标题1 值1 值1 . . . 值1
标题2 值2 值2 . . . 值2
… … … …
标题26 值26 值26 . . . 值26
在quickrep1中做以下布局:
QRLhead
QRLCH QRT1 QRT2 ... QRT5
QRL1 QRL11 QRL21 ... QRL51
QRL2 QRL12 QRL22 ... QRL52
… … … …
QRL26 QRL126 QRL226 ... QRL526
说明: QRL开头表示QRLABEL型控件
QRT开头表示QRRICHTEXT型控件,用此控件是因品名太长要求能自动换行
注意其它QRL控件的命名规则
1. 在QuickRep1之onBeforePrint写以下程序
procedure TRptForm.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
var
crecordcount:integer;
begin
crecordcount:=gbg123dm.adsrpt.RecordCount;//取记录总数
currentline:=0;
if (crecordcount mod 5) = 0 then
// 5表示栏数;
maxline:=gbg123dm.adsrpt.RecordCount // maxline表示最大行数,要先行定义;
else
maxline:=gbg123dm.adsrpt.RecordCount+5;
gbg123dm.adsrpt.First;
end;
此部分求最大打印行数,因如果总录数不能被栏数整除的话,其余的记录将不被打印,如记录有11笔,要分5栏,分栏打印出来后,应有3页;如不处理,只有2页,第11笔将不会被印出
2.在QuickRep1之onNeedData写以下程序
procedure TRptForm.QuickRep1NeedData(Sender: TObject;
var MoreData: Boolean);
var
i:integer;
begin
MoreData := True;
for i:=1 to 5do
//5表示栏数;
begin
inc(currentline);//当前
case i of
1:begin
if not gbg123dm.adsrpt.Eof then
begin
QRT1.Lines.Text:= trim(gbg123dm.adsrpt.FieldByName('a12_04').AsString)+'/'+gbg123dm.adsrpt.FieldByName('a12_07').AsString;
QRL11.Caption:=gbg123dm.adsrpt.FieldByName('a01').AsString;
QRL12.Caption:=gbg123dm.adsrpt.FieldByName('a02').AsString;
…
QRL126.Caption:=gbg123dm.adsrpt.FieldByName('a26').AsString;
end
else
begin
QRT1.Lines.Text:= '';
QRL11.Caption:='';
…
QRL126.Caption:='';
end;
end;
2:begin
if not gbg123dm.adsrpt.Eof then
begin
QRT2.Lines.Text:= trim(gbg123dm.adsrpt.FieldByName('a12_04').AsString)+'/'+gbg123dm.adsrpt.FieldByName('a12_07').AsString;
QRL21.Caption:=gbg123dm.adsrpt.FieldByName('a01').AsString;
QRL22.Caption:=gbg123dm.adsrpt.FieldByName('a02').AsString;
…
QRL226.Caption:=gbg123dm.adsrpt.FieldByName('a26').AsString;
end
else
begin
QRT2.Lines.Text:= '';
QRL21.Caption:='';
QRL22.Caption:='';
…
QRL226.Caption:='';
end;
end;
3:begin
if not gbg123dm.adsrpt.Eof then
begin
QRT3.Lines.Text:= trim(gbg123dm.adsrpt.FieldByName('a12_04').AsString)+'/'+gbg123dm.adsrpt.FieldByName('a12_07').AsString;
QRL31.Caption:=gbg123dm.adsrpt.FieldByName('a01').AsString;
QRL32.Caption:=gbg123dm.adsrpt.FieldByName('a02').AsString;
…
QRL326.Caption:=gbg123dm.adsrpt.FieldByName('a26').AsString;
end
else
begin
QRT3.Lines.Text:= '';
QRL31.Caption:='';
QRL32.Caption:='';
…
QRL326.Caption:='';
end;
end;
4:begin
if not gbg123dm.adsrpt.Eof then
begin
QRT4.Lines.Text:= trim(gbg123dm.adsrpt.FieldByName('a12_04').AsString)+'/'+gbg123dm.adsrpt.FieldByName('a12_07').AsString;
QRL41.Caption:=gbg123dm.adsrpt.FieldByName('a01').AsString;
QRL42.Caption:=gbg123dm.adsrpt.FieldByName('a02').AsString;
…
QRL426.Caption:=gbg123dm.adsrpt.FieldByName('a26').AsString;
end
else
begin
QRT4.Lines.Text:= '';
QRL41.Caption:='';
…
QRL426.Caption:='';
end;
end;
5:begin
if not gbg123dm.adsrpt.Eof then
begin
QRT5.Lines.Text:= trim(gbg123dm.adsrpt.FieldByName('a12_04').AsString)+'/'+gbg123dm.adsrpt.FieldByName('a12_07').AsString;
QRL51.Caption:=gbg123dm.adsrpt.FieldByName('a01').AsString;
QRL52.Caption:=gbg123dm.adsrpt.FieldByName('a02').AsString;
…
QRL526.Caption:=gbg123dm.adsrpt.FieldByName('a26').AsString;
end
else
begin
QRT5.Lines.Text:= '';
QRL51.Caption:='';
QRL52.Caption:='';
…
QRL526.Caption:='';
end;
end;
end;
end;
if not gbg123dm.adsrpt.Eof then
gbg123dm.adsrpt.Next;
end;
MoreData := (currentline < maxline);