我想把StringGrid数据分页打印,每页打印 22 行.
现在好像每页都会打印出22个标题,都是一行标题,一行数据.
一页也全部打满了.
以下是我的源程序,请大家帮我看看,问题是出在什么地方.
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, QRCtrls;type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
DetailBand1: TQRBand;
QRBand1: TQRBand;
QRLabel1: TQRLabel;
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2 :TForm2;
QRLabel: array of array of TQRLabel;
QRShape: array of array of TQRShape;
CurrRow,pageRow: integer; //当前行,总行数,每页的行数
GridColumn,GridCountRow:integer ;//stringGrid中的行,列
inPage: integer;implementationuses UMain;{$R *.dfm}procedure TForm2.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
var
i,j: integer;
begin
CurrRow := 1;
SetLength(QRLabel,pageRow+1,GridColumn); // 而此处应该是生成每页打印的行数,另加一个标题行
SetLength(QRShape,pageRow+1,GridColumn);
//动态创建每面的行数及Qrlabel
for j:=0 to pageRow do
begin
for i:=0 to GridColumn - 1 do
begin
QRShape[j,i]:=TQRShape.Create(self);
with QRShape[j,i] do
begin
Parent:=DetailBand1;
Left:=i*92; Top:=j*24;
Height:=25;
Width:=93;
Width := FrmMain.StringGrid1.ColWidths[i];
Enabled:=True;
Visible:=True;
end;
QRLabel[j,i]:=TQRLabel.Create(self);
with QRLabel[j,i] do
begin
Parent:=DetailBand1;
Left:=i*92+2;
Top:=j*24+6;
Height:=16;
Width:=90;
Alignment:=TaCenter;
AutoSize:=True;
Caption:='';
Enabled:=True;
Visible:=True;
end;
end;
end; //初始化第一栏标题
for i := 0 to GridColumn -1 do
QRLabel[0,i].Caption := FrmMain.StringGrid1.Cells[i,0];
end;
/******************估计出问题的就在QuickRep1NeedData这个过程*********************************//
procedure TForm2.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
var
i,j: Integer;
begin
if CurrRow > GridCountRow then // 为要打印的StringGrid行数
begin
MoreData:=False ;
exit;
end
else
begin
MoreData:=True; //连续打印
for j:=1 to pageRow do
begin
for i:=0 to GridColumn - 1 do
begin
if CurrRow > GridCountRow then
QRLabel[j,i].Caption := ''
else
QRLabel[j,i].Caption:=FrmMain.StringGrid1.Cells[i,CurrRow]; // 打印当前行对应的数据
end;
end;
Inc(CurrRow);
end;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
pageRow := 20; //每页打印20行
GridColumn := FrmMain.StringGrid1.ColCount; //StringGrid总列数
GridCountRow := FrmMain.StringGrid1.RowCount; //StringGrid 总行数
end;
end.
请大家帮我改正
问题进行扩展,如果我要在StringGrid 中实现分组功能(而且要打印),有什么好办法。因为我的数据是从文件中读取的,所以本人想在StringGrid的基础上增加一些功能.
现在好像每页都会打印出22个标题,都是一行标题,一行数据.
一页也全部打满了.
以下是我的源程序,请大家帮我看看,问题是出在什么地方.
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, QRCtrls;type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
DetailBand1: TQRBand;
QRBand1: TQRBand;
QRLabel1: TQRLabel;
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2 :TForm2;
QRLabel: array of array of TQRLabel;
QRShape: array of array of TQRShape;
CurrRow,pageRow: integer; //当前行,总行数,每页的行数
GridColumn,GridCountRow:integer ;//stringGrid中的行,列
inPage: integer;implementationuses UMain;{$R *.dfm}procedure TForm2.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
var
i,j: integer;
begin
CurrRow := 1;
SetLength(QRLabel,pageRow+1,GridColumn); // 而此处应该是生成每页打印的行数,另加一个标题行
SetLength(QRShape,pageRow+1,GridColumn);
//动态创建每面的行数及Qrlabel
for j:=0 to pageRow do
begin
for i:=0 to GridColumn - 1 do
begin
QRShape[j,i]:=TQRShape.Create(self);
with QRShape[j,i] do
begin
Parent:=DetailBand1;
Left:=i*92; Top:=j*24;
Height:=25;
Width:=93;
Width := FrmMain.StringGrid1.ColWidths[i];
Enabled:=True;
Visible:=True;
end;
QRLabel[j,i]:=TQRLabel.Create(self);
with QRLabel[j,i] do
begin
Parent:=DetailBand1;
Left:=i*92+2;
Top:=j*24+6;
Height:=16;
Width:=90;
Alignment:=TaCenter;
AutoSize:=True;
Caption:='';
Enabled:=True;
Visible:=True;
end;
end;
end; //初始化第一栏标题
for i := 0 to GridColumn -1 do
QRLabel[0,i].Caption := FrmMain.StringGrid1.Cells[i,0];
end;
/******************估计出问题的就在QuickRep1NeedData这个过程*********************************//
procedure TForm2.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
var
i,j: Integer;
begin
if CurrRow > GridCountRow then // 为要打印的StringGrid行数
begin
MoreData:=False ;
exit;
end
else
begin
MoreData:=True; //连续打印
for j:=1 to pageRow do
begin
for i:=0 to GridColumn - 1 do
begin
if CurrRow > GridCountRow then
QRLabel[j,i].Caption := ''
else
QRLabel[j,i].Caption:=FrmMain.StringGrid1.Cells[i,CurrRow]; // 打印当前行对应的数据
end;
end;
Inc(CurrRow);
end;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
pageRow := 20; //每页打印20行
GridColumn := FrmMain.StringGrid1.ColCount; //StringGrid总列数
GridCountRow := FrmMain.StringGrid1.RowCount; //StringGrid 总行数
end;
end.
请大家帮我改正
问题进行扩展,如果我要在StringGrid 中实现分组功能(而且要打印),有什么好办法。因为我的数据是从文件中读取的,所以本人想在StringGrid的基础上增加一些功能.
解决方案 »
- 生成菜单取消快捷键
- 如何设置使得TComboBox下拉列表框不能下拉(不能更改,相当与ReadOnly为True) 200410
- 现在我在query里把所有的字段又加上不出错了,但是我输2.2它给我2.200000434
- 如何判断一个数据库中存在一个指定的存储过程呢??
- 在用TWebBrowser作IE时怎么调用出象Microsoft Internet Explorer那样的“Internet选项”
- 帮忙!使用QUICKREPORT画报表,在运行怎样才能不再显示设计页面给用户?
- 请进,一个关于数据库设计的问题!很简单,送分!在线等候
- 请问,怎么才能知道tem.db这个文件的大小(字节)及A盘的剩余空间?
- DBGRID的什么事件可以当改变焦点时(换一行记录)时触发?
- ??谁用过delphi+oracle开发数据库软件
- 求助!了解htonl函数转换标准网络字序的大侠请进
- 怎样可以把DRAWGRID控件保存为图片呢?
应该Top:=6;就可以了
因为它的Parent:=DetailBand1;
top值应该是相对于DetailBand1 而言,不是相对整个报表
如果我吧MoreData:=True;这行注释掉,那就一页可以打行20行,但是数据只有一条