動態產生報表 附程式
procedure CreateTextMemo(AOwner:tComponent;x,y,w,h:integer;
MText:string;MAlign,MHAlign,MSize,MStyle,MColor:integer;
isgrid:boolean;StrFormat:string='');
begin
Memo := TfrxMemoView.Create(AOwner);
Memo.CreateUniqueName;
Memo.Text := MText;
Memo.VAlign:=vaCenter; //有可能上下合併儲存格 所以全部上下置中
Memo.WordWrap:=false; //不要自動換行 超過不顯示
case MAlign of
1:Memo.Align := baLeft;
2:Memo.Align := baWidth;
3:Memo.Align := baRight;
end;
case MHAlign of
0:Memo.HAlign := haLeft;
1:Memo.HAlign := haCenter;
2:Memo.HAlign := haRight;
end;
if MSize<>0 then
Memo.Font.Size:=MSize;
if MStyle =1 then
Memo.Font.Style:=[fsUnderline];
Memo.SetBounds(x, y, w, h);
if MColor<>0 then
Memo.Font.Color:=MColor;
if isgrid then
begin
Memo.Frame.LeftLine.Style:=fsSolid;
Memo.Frame.RightLine.Style:=fsSolid;
Memo.Frame.TopLine.Style:=fsSolid;
Memo.Frame.BottomLine.Style:=fsSolid;
Memo.Frame.Typ:=[ftRight,ftLeft,ftTop,ftBottom];
memo.Frame.Width:=Frame_width;
end;
if w=0 then
Memo.AutoWidth:=true;
if StrFormat<>'' then
Memo.DisplayFormat.FormatStr:=StrFormat;
Memo.DisplayFormat.FormatStr:='%2.2n';
end;
procedure CreateDBMemo(AOwner:tComponent;x,y,w,h:integer;
FDS:TfrxDBDataset;datafield:string;
MHAlign:integer;MColor:integer;
isgrid:boolean;StrFormat:string='');
begin
Memo := TfrxMemoView.Create(AOwner);
Memo.CreateUniqueName;
{ connect to data }
Memo.DataSet := FDS;
Memo.DataField := datafield;
Memo.SetBounds(x, y, w, h); //高度20 文字會跑到第二排
Memo.VAlign:=vaCenter; //有可能上下合併儲存格 所以全部上下置中
Memo.WordWrap:=false; //不要自動換行 超過不顯示
{ adjust the text to the right object’s margin }
case MHAlign of
0:Memo.HAlign := haLeft;
1:Memo.HAlign := haCenter;
2:Memo.HAlign := haRight;
end;
if MColor<>0 then
Memo.Font.Color:=MColor;
if isgrid then
begin
Memo.Frame.LeftLine.Style:=fsSolid;
Memo.Frame.RightLine.Style:=fsSolid;
Memo.Frame.TopLine.Style:=fsSolid;
Memo.Frame.BottomLine.Style:=fsSolid;
Memo.Frame.Typ:=[ftRight,ftLeft,ftTop,ftBottom];
memo.Frame.Width:=Frame_width;
end;
if w=0 then
Memo.AutoWidth:=true;
if StrFormat<>'' then
Memo.DisplayFormat.FormatStr:=StrFormat;
Memo.DisplayFormat.FormatStr:='%2.2n';
end;
//將Brand框起來
procedure BrandFrame(Brand:TfrxBand);
begin
Memo := TfrxMemoView.Create(Brand);
Memo.CreateUniqueName;
Memo.Align:= baClient; //<<
Memo.Text:='';
Memo.Frame.LeftLine.Style:=fsSolid;
Memo.Frame.RightLine.Style:=fsSolid;
Memo.Frame.TopLine.Style:=fsSolid;
Memo.Frame.BottomLine.Style:=fsSolid;
Memo.Frame.Typ:=[ftRight,ftLeft,ftTop,ftBottom];
Memo.Frame.Width:=Frame_width;
end;
//程式碼部分
{$REGION 'Report'}
{ clear a report }
frxReport.Clear;
frxReport.DataSets.Clear;
frxReport.DataSets.Add(Dataset1);
frxReport.DataSets.Add(Dataset2);
{ add a page }
Page := TfrxReportPage.Create(frxReport);
{ create a unique name }
Page.CreateUniqueName;
{ set sizes of fields, paper and orientation by default }
Page.SetDefaults;
Page.PaperWidth:=210;
Page.PaperHeight:=279.4;
{ modify paper’s orientation }
Page.Orientation := poLandscape; //橫式
BandWidth:=Round((Page.PaperWidth)*10);
{$ENDREGION}
//報表抬頭
{$REGION 'TITLE'}
{ add a report title band}
Band := TfrxReportTitle.Create(Page);
Band.CreateUniqueName;
{ it is sufficient to set the ?Top? coordinate and height for a band }
{ both coordinates are in pixels }
Band.Top := 0;
Band.Height := 40;
{ add an object to the report title band }
Memo := TfrxMemoView.Create(Band);
Memo.CreateUniqueName;
Memo.Text := '報表抬頭'
Memo.Height := 30;
Memo.Align := baCenter;
Memo.HAlign:= haCenter;
Memo.AutoWidth:=True;
Memo.Font.Size:=14;
Memo.Font.Name:='微軟正黑體';
Memo.Frame.BottomLine.Style:=fsDouble;
Memo.Frame.Typ:=[ftbottom];
{$ENDREGION}
//建立表頭
{$REGION 'PageHeaderBand'}
PageHeaderBand:=TfrxPageHeader.Create(page);
PageHeaderBand.CreateUniqueName;
PageHeaderBand.Top := 100;
PageHeaderBand.Height:=PageHeaderRowHeigth*3+ 10;
//PageHeaderBand.StartNewPage:=False;
// loop Start
CreateTextMemo(
PageHeaderBand,
l,t,w,h,
PageHeaderRowHeigth,
Templist.Names[i]+' : ',0,2,0,0,0,
false
);
CreateTextMemo(
PageHeaderBand,
l,t,w,h,
PageHeaderRowHeigth,
Templist.ValueFromIndex[i],0,0,0,0,0,
false
);
//loop end
BrandFrame(PageHeaderBand);
{$ENDREGION}
//建立MasterData
{$REGION 'MasterData'}
{ add the masterdata band }
MasterDataBand := TfrxMasterData.Create(Page);
//DataBand.Name:='MasterData1';
MasterDataBand.CreateUniqueName;
MasterDataBand.DataSet := frxDBDS_OrderMst;
MasterDataBand.Height := {高度};
{ the Top coordinate should be greater than the previously added band’s
top + height}
MasterDataBand.Top := 300;
//MasterDataBand.PrintIfDetailEmpty:=True; //明細空的也要印
CreateTextMemo(
MasterDataBand,
l,t,w,h,
LanguageTS.Values['remark']+' : ',0,2,0,0,0,False);
CreateDBMemo(
MasterDataBand,
l,t,w,h,
frxDBDS_OrderMst,
'remark',
0,0,False
);
//畫框線 (上)
Line:=TfrxLineView.Create(MasterDataBand);
Line.CreateUniqueName;
Line.Parent:=MasterDataBand;
Line.Left:=0;
Line.Top:=MasterDataBandHeadBevel; //間隔後畫一條線
Line.Width:=980.00; //橫式
Line.Frame.Width:=1;
//畫框線 (左)
Line:=TfrxLineView.Create(MasterDataBand);
Line.CreateUniqueName;
Line.Parent:=MasterDataBand;
Line.Left:=0;
Line.Top:=MasterDataBandHeadBevel; //間隔後畫一條線
Line.Height:=MasterDataBand.Height-MasterDataBandHeadBevel;
Line.Frame.Width:=1;
//畫框線 (右)
Line:=TfrxLineView.Create(MasterDataBand);
Line.CreateUniqueName;
Line.Parent:=MasterDataBand;
Line.Left:=980;
Line.Top:=MasterDataBandHeadBevel; //間隔後畫一條線
Line.Height:=MasterDataBand.Height-MasterDataBandHeadBevel;
Line.Frame.Width:=1;
//畫框線 (下)
Line:=TfrxLineView.Create(MasterDataBand);
Line.CreateUniqueName;
Line.Parent:=MasterDataBand;
Line.Left:=0;
Line.Top:=MasterDataBand.Height; //間隔後畫一條線
Line.Width:=980.00; //橫式
Line.Frame.Width:=1;
{$ENDREGION}
//以下自行發揮
//最後預覽報表
{ show the report }
frxReport.ShowReport;
以下為一些特殊動態設定
設定Memo Format
千分位 並顯示小數後兩位
Memo.DisplayFormat.Kind:=fkNumeric; //<<必須指定這個 不然Format無效
Memo.DisplayFormat.FormatStr:='%2.2n';
留言列表