1、FastReport4 动态报表制作FastReport4动态报表制作注:1、窗体报表控件FR:TfrxReport;frDB:TfrxDBDataset2、调用自定义函数:GetPrnFieldWidth(ADOQ_List); /取得查询结果中各字段宽度3、全局变量:Prn_FieldWidth: Arrayofinteger; /打印时各字段宽度数组通过GetPrnFieldWidth修改其值4、usesPRINTERS;代码:procedureTFrm_yppf_prn_pfd.ToolButton3Click(Sender: TObject);Var/DataPage: TfrxDa
2、taPage;Page: TfrxReportPage;PageTitle:TfrxReportTitle;PageHeader:TfrxPageHeader;/Band: TfrxBand;MastData: TfrxMasterData;PageSummary:TfrxReportSummary;Memo: TfrxMemoView;i:integer;MLeft:Real;/表头字段在mastdata中的左边距PaperWidth:Real; /纯报表(不含边距)宽度(毫米)begin/清除报表FR.Clear;/1=添加页Page:=TfrxReportPage.Create(FR);
3、Page.CreateUniqueName;/创建唯一名称/Page.SetDefaults;/设置默认字段大小,纸张/自定义纸张大小/Page.PaperWidth:=210; /纸张宽/Page.PaperHeight:=297;/纸张高Page.PaperSize:=9;/a4纸Page.Orientation:=poPortrait; /纸张纵向/Page.Orientation:=poLandscape; /纸张横向Page.TopMargin:=25;/上边距Page.BottomMargin:=15;Page.LeftMargin:=15;Page.RightMargin:=15
4、;/2=添加一个报表标题栏PageTitle:=TfrxReportTitle.Create(Page);PageTitle.CreateUniqueName;PageTitle.Top:=0;PageTitle.Height:=140;/留出空白行/得到报表不含边距的宽度(毫米)转换为像素时需乘以3.77953/SetBounds中用的是像素值PaperWidth:=(Page.PaperWidth-page.LeftMargin-page.RightMargin)*3.77953;/添加标题memoMemo:= TfrxMemoView.Create(PageTitle);Memo.Cre
5、ateUniqueName;Memo.HAlign:=haCenter;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Font.Size:=14;Memo.Text := 药品批发单;Memo.Height := 40;Memo.Align:=baWidth;/伸展坐标到标题栏的宽度/摘要第一行Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 单号:+LEdit_dh.
6、Hint;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(0,60,PaperWidth/3,20);/Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 单位:+LEdit_dwmc.Text;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ft
7、Right,ftTop,ftBottom;/显示边线Memo.SetBounds(PaperWidth/3,60,PaperWidth/3,20);/Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 批发金额:+LEdit_SumPfj.Text;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.Se
8、tBounds(PaperWidth/3*2,60,PaperWidth/3,20);/摘要第二行Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 结算方式:+LEdit_jsfsmc.Text;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(0,80,PaperWidth/3,
9、20);/Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 制单人:+LEdit_zdr.Text;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(PaperWidth/3,80,PaperWidth/3,20);/Memo:= TfrxMemoView.Create(PageT
10、itle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 制单日期:+LEdit_zdrq.Text;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(PaperWidth/3*2,80,PaperWidth/3,20);/摘要第三行Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;
11、Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := 操作员:+UserName;Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(0,100,PaperWidth/3,20);/Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中M
12、emo.Text := 打印日期:+DateToStr(Date)+TimeToStr(GetTime);Memo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(PaperWidth/3,100,PaperWidth/3,20);/Memo:= TfrxMemoView.Create(PageTitle);Memo.CreateUniqueName;Memo.HAlign:=haLeft;/左右居中Memo.VAlign:=vaCenter;/上下居中Memo.Text := ;Me
13、mo.Height := 20;Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.SetBounds(PaperWidth/3*2,100,PaperWidth/3,20);/=3=添加Pageheader(表头)PageHeader:=TfrxPageHeader.Create(Page);PageHeader.CreateUniqueName;/PageHeader.Top:=PageTitle.Height+120; /其总是紧随PageTitle之后PageHeader.Height:=20;/添加表头memoGetPrnF
14、ieldWidth(ADOQ_List); /取得查询结果中各字段宽度MLeft:=0;for i := 0 to ADOQ_List.FieldCount - 1 doBeginMemo:=TfrxMemoView.Create(PageHeader);Memo.CreateUniqueName;Memo.HAlign:=haCenter;Memo.HAlign:=haCenter;Memo.VAlign:=vaCenter;/上下对齐Memo.Frame.TopLine.Style:=fsSolid;Memo.Frame.BottomLine.Style:=fsSolid;Memo.Fra
15、me.LeftLine.Style:=fsSolid;Memo.Frame.RightLine.Style:=fsSolid;/边线格式Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.Text:=Trim(ADOQ_List.Fieldsi.FieldName);ifiADOQ_List.FieldCount-1 thenBeginMemo.SetBounds(MLeft,0,Prn_FieldWidthi*7.5,20);EndElseBegin /最后一列时,页面剩余宽度都给他Memo.SetBounds(MLeft,0,Pa
16、perWidth-MLeft,20);End;MLeft:=MLeft+Prn_FieldWidthi*7.5;/下一列左起位置End;/4=主数据(记录)MastData:=TfrxMasterData.Create(Page);MastData.CreateUniqueName;MastData.Top:=PageTitle.Height+PageHeader.Height;MastData.Height:=20;MastData.DataSet:=frDB;/添加memoMLeft:=0;for i := 0 to ADOQ_List.FieldCount - 1 doBeginMemo
17、:=TfrxMemoView.Create(MastData);Memo.CreateUniqueName;/Memo.HAlign:=haCenter;Memo.HAlign:=haLeft;Memo.VAlign:=vaCenter;/上下对齐Memo.Font.Size:=9;Memo.Frame.TopLine.Style:=fsSolid;Memo.Frame.BottomLine.Style:=fsSolid;Memo.Frame.LeftLine.Style:=fsSolid;Memo.Frame.RightLine.Style:=fsSolid;/边线格式Memo.Frame.Typ:=ftLeft,ftRight,ftTop,ftBottom;/显示边线Memo.DataSet:=frDB;Memo.DataField:=Trim(ADOQ_List.Fieldsi.FieldName);ifi0 thenBeginif StrToInt(DM.ADOQ_Find.FieldByName(字段最长值).AsString)Prn_FieldWidthi thenPrn_FieldWidthi:=StrToInt(DM.ADOQ_Find.FieldByName(字段最长值).AsString);End;MyADOQ.Next;End;End;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1