Qreport 填满最后一页的空白

通常情况下,可以考虑用qrloopband来。qrloopband设计时一般在detailband之后,可以通过qrloopband.enable来控制qrloopband的显示与否,在最后一页计算需要多少行空白页,然后将qrloopband.enable:=true,并且设计qrloopband.printcount:=行数。

我是在动态生成报表的情况下,quickrep等所有组件都是动态生成的。如果使用qrloopband,始终无法控制qrloopband的位置在detailband后,并且跟着detailband打印。所以最后使用detailband.childband(将detailband.haschild:=true)。也是通过控制enable来控制显示。先quickrep.prepare,并在最后一页时计算行数n,然后quickrep.preview,在最后一行时根据刚才的计算动态生成n行qrshape(表示表格线)。

程序如下:(有些部门非必须,是测试用的,待注释)

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QuickRpt, QRCtrls, DB, ADODB, ExtCtrls;

type
TForm1 = class(TForm)
QuickRep1: TQuickRep;
DetailBand1: TQRBand;
ADOTable1: TADOTable;
QRDBText1: TQRDBText;
ChildBand1: TQRChildBand;
QRLabel1: TQRLabel;
SummaryBand1: TQRBand;
procedure DetailBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
procedure DetailBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
procedure ChildBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
procedure ChildBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
procedure FormCreate(Sender: TObject);
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
private
{ Private declarations }
lt:TStrings;
index:Integer;
j:Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DetailBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
lt.Add('detailb'+':'+inttostr(QuickRep1.CurrentY));
end;

procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
var
I: Integer;
sh :TQRshape;
begin
lt.Add('detaila:'+inttostr(QuickRep1.CurrentY));
// if QuickRep1.RecordCount=QuickRep1.RecordNumber then
// begin
// ChildBand1.Enabled := true;
//
// end
// else
// ChildBand1.Enabled := false;

ChildBand1.Enabled := false;
if index=1 then
begin

if QuickRep1.RecordCount=QuickRep1.RecordNumber then
begin

if QuickRep1.CurrentY+QuickRep1.Bands.SummaryBand.Size.Height+40<
QuickRep1.Page.Length-QuickRep1.Page.BottomMargin then
begin
j := trunc((QuickRep1.Page.Length-QuickRep1.Page.BottomMargin-
QuickRep1.CurrentY-QuickRep1.Bands.SummaryBand.Size.Height) / (106) );

QuickRep1.Bands.DetailBand.ChildBand.Enabled := true;
end;
end;
end
else begin

if QuickRep1.RecordCount=QuickRep1.RecordNumber then
begin
QuickRep1.Bands.DetailBand.ChildBand.Enabled := true;

end
else
QuickRep1.Bands.DetailBand.ChildBand.Enabled := false;

end;

end;

procedure TForm1.ChildBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
begin
lt.Add('ca');
end;

procedure TForm1.ChildBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
lt.Add('cb');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
lt := TStringList.Create;
index := 1;
QuickRep1.Prepare;
index := 2;
QuickRep1.PreviewModal;
lt.SaveToFile('I:/tmp/theight.txt');
lt.Free;

end;

procedure TForm1.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
var
sh:TQRShape;
i:Integer;
begin
if index=2 then
begin
for I := 0 to j - 1 do // Iterate
begin
sh := TQRShape.Create(nil);
sh.Parent := QuickRep1.Bands.DetailBand.ChildBand;
sh.Top := 40*i;
sh.Left := 10;
sh.Width := 300;
sh.Height := 41;


end; // for

QuickRep1.Bands.DetailBand.ChildBand.Height := 40 * j+2;
end;

end;

end.

你可能感兴趣的:(port)