我用公司的一个打印构件,打印A4时没有问题,但是打印A3换页时最后一行漏了。为什么??(我只有这么多分了)(10分)

  • 主题发起人 luosheng
  • 开始时间
L

luosheng

Unregistered / Unconfirmed
GUEST, unregistred user!
我用公司的一个打印构件,打印A4时没有问题,但是打印A3换页时最后一行漏了。
小弟实在是看不出为什么。你能说出理由吗,或者你帮我看原代码。编写该构件
的人已经离开公司了。我只有这点分了!
代码如下:
unit WlReport;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, QuickRpt, QRCTRLS, QRextra, qrprntr, Printers, db, dbtables,
dbgrids;
type
TWlReport = Class(TComponent)
private
{private declarations}
FTitle: String;
FSubTitle: String;
FDBGrid: TDBGrid;
FTopLeft: String;
FTopCenter: String;
FTopRight: String;
FBottomLeft: String;
FBottomCenter: String;
FBottomRight: String;
FDataFont: TFont;
FTitleFont: TFont;
FSubTitleFont: TFont;
FPageType: TQRPaperSize;
FPageAlignment: TAlignment;
FPageOrientation: TPrinterOrientation;
procedure SetDataFont(Value: TFont);
procedure SetTitleFont(Value: TFont);
procedure SetSubTitleFont(Value: TFont);
function Calculate_DBGridWidth: Integer;
//计算DBGrid的宽度
function Calculate_BandsLeft: Integer;
//计算打印页的左边位置
public
{Public declarations}
CurrentReport: TQuickRep;
DBGrid_Width, BandsLeft: Integer;
MyQRShape, MyDetailQRShape: TQRShape;
MyQRDBText: TQRDBText;
MyQRLabel: TQRLabel;
procedure CreatePrintData;
//创建打印数据
procedure CreateReportTitle;
//创建报表题头
procedure CreateReportDetail;
//创建报表明细
protected
{protected declarations}
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
{published declarations}
property Title: String Read FTitle Write FTitle;
//报表标题
property SubTitle: String Read FSubTitle Write FSubTitle;
//报表子标题
property DBGrid: TDBGrid Read FDBGrid Write FDBGrid;
//数据集控件
property TopLeft: String Read FTopLeft Write FTopLeft;
//表头左边显示
property TopCenter: String Read FTopCenter Write FTopCenter;
//表头中间显示
property TopRight: String Read FTopRight Write FTopRight;
//表头右边显示
property BottomLeft: String Read FBottomLeft Write FBottomLeft;
//表尾左边显示
property BottomCenter: String Read FBottomCenter Write FBottomCenter;
//表尾中间显示
property BottomRight: String Read FBottomRight Write FBottomRight;
//表尾右边显示
property DataFont: TFont Read FDataFont Write SetDataFont;
//数据字体
property TitleFont: TFont Read FTitleFont Write SetTitleFont;
//报表标题字体
property SubTitleFont: TFont Read FSubTitleFont Write SetSubTitleFont;
//报表子标题字体
property PageType: TQRPaperSize Read FPageType Write FPageType;
//报表纸张类型
property PageAlignment: TAlignment Read FPageAlignment Write FPageAlignment;
//报表对齐方式
property PageOrientation: TPrinterOrientation Read FPageOrientation
Write FPageOrientation;
//报表打印方向
end;

procedure Register;
implementation
{$R WlReport.dcr}
procedure Register;
begin
RegisterComponents('王黎', [TWlReport]);
end;

{ TWlReport }
constructor TWlReport.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTitleFont := TFont.Create;
FTitleFont.Size := 12;
FTitleFont.Name := '宋体';
FSubTitleFont := TFont.Create;
FSubTitleFont.Size := 12;
FSubTitleFont.Name := '宋体';
FDataFont := TFont.Create;
FDataFont.Size := 9;
FDataFont.Name := '宋体';
FPageAlignment := taCenter;
FPageType := A4;
FPageOrientation := poPortrait;
end;

destructor TWlReport.Destroy;
begin
FTitleFont.Free;
FTitleFont := Nil;
FSubTitleFont.Free;
FSubTitleFont := Nil;
FDataFont.Free;
FDataFont := Nil;
inherited Destroy;
end;

procedure TWlReport.SetDataFont(Value: TFont);
begin
FDataFont.Assign(Value);
end;

procedure TWlReport.SetSubTitleFont(Value: TFont);
begin
FSubTitleFont.Assign(Value);
end;

procedure TWlReport.SetTitleFont(Value: TFont);
begin
FTitleFont.Assign(Value);
end;

//创建打印数据
procedure TWlReport.CreatePrintData;
var
i, ColumnHeaderLeft: Integer;
iTitleWidth, iPos: Integer;
begin
If DBGrid = Nil then
begin
ShowMessage('请指定DBGrid属性');
abort;
end;

If DBGrid.DataSource.DataSet = Nil then
begin
ShowMessage('请指定数据源');
Abort;
end;

CreateReportTitle;
CurrentReport.Font := DBGrid.Font;
CurrentReport.Bands.ColumnHeaderBand.Height := 25;
CurrentReport.Bands.DetailBand.Height := 20;
DBGrid_Width := Calculate_DBGridWidth;
BandsLeft := Calculate_BandsLeft;
ColumnHeaderLeft := BandsLeft;
for i := 0 to DBGrid.Columns.Count - 1do
begin

if DBGrid.Columns.Visible then
begin

MyQRShape := TQRShape.Create(Self);
with MyQRShapedo
begin
Parent := CurrentReport.Bands.ColumnHeaderBand;
Width := DBGrid.Columns.Width;
Height := 25;
Left := ColumnHeaderLeft;
Pen.Width := 2;
end;

MyQRLabel := TQRLabel.Create(Self);
with MyQRLabeldo
begin
Parent := CurrentReport.Bands.ColumnHeaderBand;
Caption := DBGrid.Columns.Title.Caption;
Font := DBGrid.Columns.Title.Font;
iTitleWidth := Width;
case DBGrid.Columns.Title.Alignment of
taLeftJustify: iPos := 3;
taCenter: iPos := (DBGrid.Columns.width - iTitleWidth) div 2;
taRightJustify: iPos := DBGrid.Columns.Width - iTitleWidth - 3;
end;

left := ColumnHeaderLeft + iPos;
Top := 5;
end;

MyDetailQRShape := TQRShape.Create(Self);
with MyDetailQRShapedo
begin
Parent := CurrentReport.Bands.DetailBand;
Width := DBGrid.Columns.Width;
Left := ColumnHeaderLeft;
Height := 20;
Top := 0;
Pen.Width := 2;
end;

MyQRDBText := TQRDBText.Create(Self);
with MyQRDBTextdo
begin
Parent := CurrentReport.Bands.DetailBand;
DataSet := DBGrid.DataSource.DataSet;
DataField := DBGrid.Columns.FieldName;
Font.Color := DBGrid.Columns.Font.Color;
AutoSize := False;
Width := DBGrid.Columns.Width - 4;
Alignment := DBGrid.Columns.Alignment ;
Left := ColumnHeaderLeft + 2;
Top := 2;
end;

ColumnHeaderLeft := ColumnHeaderLeft + DBGrid.Columns.Width;
end;
end;
CreateReportDetail;
end;

//创建报表题头
procedure TWlReport.CreateReportTitle;
begin
CurrentReport := Nil;
CurrentReport := TQuickRep.Create(Self);
with CurrentReportdo
begin
DataSet := DBGrid.DataSource.DataSet;
Units := Pixels;
//定义页面宽度参数为象素
Page.PaperSize := FPageType;
//定义纸张类型
Page.Orientation := FPageOrientation;
//定义纸张方向
Page.TopMargin := 20;
Page.BottomMargin := 20;
Page.LeftMargin := 0;
Page.RightMargin := 0;
Font := DBGrid.Font;
//定义字体
Bands.HasPageHeader := True;
//页头
Bands.PageHeaderBand.ClientHeight := 110;
Bands.HasColumnHeader := True;
Bands.ColumnHeaderBand.ClientHeight := 24;
Bands.HasDetail := True;
Bands.DetailBand.ClientHeight := 24;
Bands.HasSummary := True;
Bands.SummaryBand.ClientHeight := 25;
end;
end;

//创建报表明细
procedure TWlReport.CreateReportDetail;
begin
with CurrentReport, CurrentReport.Bandsdo
begin

//标题
with PageHeaderBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := True;
Alignment := taCenter;
AutoSize := True;
Top := 7;
Caption := Title;
Font := TitleFont;
end;

//子标题
with PageHeaderBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := True;
Alignment := taCenter;
AutoSize := True;
Top := 51;
Caption := SubTitle;
Font := SubTitleFont;
end;

//打印页页头左边显示
with PageHeaderBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand:= False;
Alignment := taLeftJustify;
AutoSize := True;
Top := 89;
Left := BandsLeft;
Caption := TopLeft;
Font := DataFont;
end;

//打印页页头中间显示
with PageHeaderBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := True;
Alignment := taCenter;
AutoSize := True;
Top := 89;
Caption := TopCenter;
Font := DataFont;
end;

//打印页页头右边显示
with PageHeaderBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := False;
Alignment := taRightJustify;
AutoSize := True;
Top := 89;
Caption := TopRight + ' 页:';
Font := DataFont;
Left := BandsLeft + DBGrid_Width - Width - 35;
end;

//定义页数
with PageHeaderBand.AddPrintable(TQRSysData) as TQRSysDatado
begin
AlignToBand := False;
Alignment := taCenter;
AutoSize := True;
Top := 89;
Font := DataFont;
Data := qrsPageNumber;
Left := BandsLeft + DBGrid_Width - Width;
end;

//打印页页尾左边显示
with SummaryBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := False;
Alignment := taLeftJustify;
AutoSize := True;
Top := 10;
Font := DataFont;
Caption := BottomLeft;
Left := BandsLeft;
end;

//打印页页尾中间显示
with SummaryBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := True;
Alignment := taCenter;
AutoSize := True;
Top := 10;
Font := DataFont;
Caption := BottomCenter;
end;

//打印页页尾右边显示
with SummaryBand.AddPrintable(TQRLabel) as TQRLabeldo
begin
AlignToBand := False;
Alignment := taRightJustify;
AutoSize := True;
Top := 10;
Font := DataFont;
Caption := BottomRight;
Left := BandsLeft + DBGrid_Width - Width;
end;

end;
end;

//得到DBGrid的宽度
function TWlReport.Calculate_DBGridWidth: Integer;
var
i, DBGridWidth: Integer;
begin
DBGridWidth := 0;
for i := 0 to DBGrid.Columns.Count - 1do
begin
if DBGrid.Columns.Visible then

DBGridWidth := DBGridWidth + DBGrid.Columns.Width;
end;

Result := DBGridWidth;
end;

//计算打印页的左边位置
function TWlReport.Calculate_BandsLeft: Integer;
begin
if PageAlignment = TaCenter then
begin
Result := Trunc((CurrentReport.Page.Width - DBGrid_Width) / 2);
if Result < 15 then
Result := 15;
end
else
Result := 15;
end;

end.
 
你把打印机改成EPSON LQ-1500就可以了
 
问题解决了!
加一个打印的页尾就可以了!
 
顶部