请问:如何动态创建报表?

WWWWA 2002-06-14 12:04:07
在一个报表中只有一个DETAILBAND,数人QRLABEL、QRTEXT,
请问如何在程序中动态设置?
谢谢!
...全文
131 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mengli1 2002-06-14
  • 打赏
  • 举报
回复
简单,你自己创建QRLABEL,自己来控制写.我以前做的是一个鞋业领料单,中间有许多SIZE是
空的,要将这些空的去掉,后面的往前靠,而且分三排.用DataSet来做根本不可能,就自己写
着来控制就行了.部分代码如下:你看了应该就知道怎么做了.用QuickRep完全能够做到.

procedure TFrmQrt.CreateQRTxt;//动态建立各QR控件,只建立一次,在准备预览或打印之前.
var i,j:integer;
begin
SetLength(QRtxt,5,txtTotal);
for i:=0 to 4 do
for j:=0 to txtTotal-1 do
begin
QRtxt[i,j]:=TQRLabel.Create(Self);
QRtxt[i,j].Parent:=DetailBand1;
QRtxt[i,j].Caption:='';
QRtxt[i,j].AutoSize:=False;
QRtxt[i,j].Width:=txtWidth;
QRtxt[i,j].Height:=txtHeight;
QRtxt[i,j].Font.Name:='新細明體';
QRtxt[i,j].Font.Size:=11;
end;
for i:=0 to txtTotal-1 do
QRtxt[0,i].Alignment:=taCenter;
for i:=0 to 35 do
QRtxt[1,i].Alignment:=taCenter;
DrawLine;
for j:=32 to 35 do
begin
Qrtxt[0,j].Font.Size:=11;
Qrtxt[1,j].Font.Size:=11;
QRtxt[0,j].Top:=StrTop;
QRtxt[1,j].Top:=StrTop;
end;
QRtxt[0,32].Left:=0;
QRtxt[1,32].Left:=60;
QRtxt[0,33].Left:=150;
QRtxt[1,33].Left:=220;
QRtxt[0,34].Left:=310;
QRtxt[1,34].Left:=380;
QRtxt[0,35].Left:=480;
QRtxt[1,35].Left:=550;
QRtxt[0,32].Width:=60;
QRtxt[1,32].Width:=90;
QRtxt[0,33].Width:=70;
QRtxt[1,33].Width:=90;
QRtxt[0,34].Width:=70;
QRtxt[1,34].Width:=100;
QRtxt[0,35].Width:=70;
QRtxt[1,35].Width:=122;
for j:=0 to 15 do
begin
QRtxt[0,j].Left:=txtWidth*j;
QRtxt[1,j].Left:=txtWidth*j;
QRtxt[2,j].Left:=txtWidth*j;
QRtxt[3,j].Left:=txtWidth*j;
QRtxt[4,j].Left:=txtWidth*j;
QRtxt[0,j].Top:=txtTop;
QRtxt[1,j].Top:=txtTop+txtHeight;
QRtxt[2,j].Top:=txtTop+txtHeight*2;
QRtxt[3,j].Top:=txtTop+txtHeight*3;
QRtxt[4,j].Top:=txtTop+txtHeight*4;
end;
for j:=16 to 31 do
begin
QRtxt[0,j].Left:=txtWidth*(j-16);
QRtxt[1,j].Left:=txtWidth*(j-16);
QRtxt[2,j].Left:=txtWidth*(j-16);
QRtxt[3,j].Left:=txtWidth*(j-16);
QRtxt[4,j].Left:=txtWidth*(j-16);
QRtxt[0,j].Top:=txtTop+txtHeight*5+20;
QRtxt[1,j].Top:=txtTop+txtHeight*6+20;
QRtxt[2,j].Top:=txtTop+txtHeight*7+20;
QRtxt[3,j].Top:=txtTop+txtHeight*8+20;
QRtxt[4,j].Top:=txtTop+txtHeight*9+20;
end;
for i:=2 to 4 do
for j:=32 to 35 do
QRtxt[i,j].Free;
end;

procedure TFrmQrt.DrawLine;//因为我打印的是表格,所以要画线,一个QRLabel中可以画框线,我就选的这个.而且,我都是用的QRLabel来实现的,加上数据源就不能这么动态了.
var i,j:integer;
begin
for i:=0 to 4 do
for j:=0 to txtTotal-1 do
begin
QRtxt[i,j].Frame.DrawTop:=True;
QRtxt[i,j].Frame.DrawLeft:=True;
end;
for j:=0 to 31 do
QRtxt[4,j].Frame.DrawBottom:=True;
QRtxt[1,35].Frame.DrawRight:=True;
QRtxt[0,15].Frame.DrawRight:=True;
QRtxt[1,15].Frame.DrawRight:=True;
QRtxt[0,31].Frame.DrawRight:=True;
QRtxt[1,31].Frame.DrawRight:=True;
QRtxt[2,15].Frame.DrawRight:=True;
QRtxt[3,15].Frame.DrawRight:=True;
QRtxt[4,15].Frame.DrawRight:=True;
QRtxt[2,31].Frame.DrawRight:=True;
QRtxt[3,31].Frame.DrawRight:=True;
QRtxt[4,31].Frame.DrawRight:=True;
for j:=32 to 35 do
QRtxt[1,j].Alignment:=taLeftJustify;
QRtxt[0,32].Caption:='單據號';
QRtxt[0,33].Caption:='台 指 號';
QRtxt[0,34].Caption:='物料代號';
QRtxt[0,35].Caption:='部門名稱';
end;

procedure TFrmQrt.GetStyleData;//在这个里面就是一笔一笔的赋值,每一笔资料都能动态的改变,当然,你也可以改成哪个显示,哪个不显示.
var i,j,x:integer;
StyleData:array of array of string;
OrdData:array of array of string;
begin
SetLength(StyleData,2,36);
SetLength(OrdData,2,32);
QStyle:=DM.PDM.QryTemp;
QStyle.Active:=False;
QStyle.SQL.Text:='select a.*,b.* from ord a,style b where (a.fno=:fno) and (a.sty_no=b.no(+))';//取得数据,
QStyle.Params[0].AsString:=QPrn.FieldByName('fno').AsString;
QStyle.Active:=True;
x:=0;
if QPrn.FieldByName('times').AsInteger>0 then
QRTimes.Caption:='重印:'+IntToStr(QPrn.FieldByName('times').AsInteger)
else
QRTimes.Caption:='新單';
for i:=0 to 35 do
if Length(QStyle.Fields[105+i].AsString)>0 then
begin
StyleData[0,x]:=QStyle.Fields[105+i].AsString;
StyleData[1,x]:=QPrn.Fields[7+i].AsString;
x:=x+1;
end;
for i:=0 to 31 do
for j:=0 to 35 do
if (Length(QStyle.Fields[24+i*2].AsString)<=0) then
break
else
if QStyle.Fields[24+i*2].AsString=StyleData[0,j] then
begin
OrdData[0,i]:=StyleData[0,j];
OrdData[1,i]:=StyleData[1,j];
break;
end;
for j:=32 to 35 do
QRtxt[1,j].Caption:='';
QRtxt[1,32].Caption:=QPrn.Fields[0].AsString;
QRtxt[1,33].Caption:=' '+QPrn.Fields[2].AsString;
QRtxt[1,34].Caption:=' '+QPrn.Fields[3].AsString;
QRtxt[1,35].Caption:=' '+QPrn.FieldByName('depna').AsString;
for i:=0 to 1 do
for j:=0 to 31 do
QRtxt[i,j].Caption:='';
for i:=0 to 31 do
if OrdData[0,i]<>'' then begin
QRtxt[0,i].Caption:=OrdData[0,i];
QRtxt[1,i].Caption:=OrdData[1,i];
end
else
break;
end;

procedure TFrmQrt.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);//QR的OnNeedData事件
begin
if not QPrn.Eof then
MoreData:=True
else if QPrn.Eof then
MoreData:=False;
if MoreData then begin
GetStyleData;//这儿便是给各个QRLAbel赋值,
QPrn.Next;//然后转到下一笔.
end
else
begin
QuickRep1.QRPrinter.Progress := 100;
QPrn.First;
end;
end;
luoweicaisd 2002-06-14
  • 打赏
  • 举报
回复
设置什么

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧