网上文摘 最近更新 下载排行 资源分类 下载指南
经典编程资源 精彩不容错过
设为首页
加入收藏
联系我们
当前位置:Delphi园地技巧文章控件使用 → StringGrid打印报表(FastReport)
StringGrid打印报表(FastReport)
日期:2005-08-02 作者:kxy 人气: 查看:[大字体 中字体 小字体]

{*************StringGrid打印功能***********************************}
(*uses unit: FR_Class, FR_View from (fast-Report) *)
(*参数说明:printRow:每页打印的行数 *)
(* styleType:边框类型 0:无边框,15:所有边框,18:底部画线 *)
(* title:标题 *)
(* FrmGrid:所在窗体 *)
(*date:2005-04-24 *)
(*author:kxy *)
{******************************************************************}
function GridPrint(Grid1:TstringGrid;printRow,StyleType:integer;Title:string;FrmGrid:TForm):boolean;//打印报表
var
fr: TfrReport;
ReportTitle,Masterdata,ColumnHeader,PageHeader,pageFooter:Tfrbandview; //栏目
MemoVT,MemoVC:Array of TfrMemoview; //列
TitleV ,dateV,pageV:TfrMemoview ;
lineV:TfrlineView; //线
page:Tfrpage; //页
GridRow,GridCol,CurrRow,I,J,col:integer;//总的行数,列数,当前行
PageCount,pageRow:integer; //总共页数;
Left,Top,Width,Heigth:integer;
TempLeft,TempWidth:integer;
printDate :string;
begin
screen.Cursor := crHourGlass;
GridRow := Grid1.RowCount;
GridCol := Grid1.ColCount;
CurrRow := 0;
pageRow := printRow;
try
fr := TfrReport.Create(FrmGrid);
fr.StoreInDFM := True;
PageCount := GridRow div printRow ; //计算出页数
for I := 0 to PageCount - 1 do
begin
left :=0;
top :=20;
width :=757;
heigth :=25;
fr.Pages.Add;
page := fr.Pages[i];
if I = 0 then //第一页增加标题;
begin
{标题栏}
ReportTitle := Tfrbandview.Create;
ReportTitle.BandType := btReportTitle;
ReportTitle.SetBounds(left,top,width,40);
page.Objects.Add(ReportTitle);
TitleV := TfrMemoview.Create;
Titlev.SetBounds(0,top,width,30);
Titlev.Alignment := (Titlev.Alignment and $FC) + 2;//居中
Titlev.Font.Name := '宋体';
TitleV.Font.Size := 16;
TitleV.Memo.Add(title);
page.Objects.Add(TitleV);
{打印日期}
dateV := TfrMemoview.Create;
dateV.SetBounds(0,top + 40,width,30);
dateV.Alignment := (dateV.Alignment and $FC) + 1 ;//右对齐
dateV.Font.Name := '宋体';
dateV.Font.Size := 9;
printDate :='打印日期:' + FormatDateTime('yyyy/mm/dd',Now) +' ';
dateV.Memo.Add(printDate);
page.Objects.Add(dateV);
PageRow := PageRow - 4 ; //少打两行组成一个标题
Top := 60;
end
ELSE
begin
pageRow := PrintRow;
Top := 20;
end;
for J:= 0 to PageRow + 1 do //每页的行数
begin
{列头}
IF J = 0 then //第一行打行列标题栏
begin
ColumnHeader := Tfrbandview.Create;
ColumnHeader.BandType := btColumnHeader;
ColumnHeader.SetBounds(left,top,width,heigth);
page.Objects.Add(ColumnHeader);
SetLength(MemoVT,GridCol);
TempLeft := 20;
for col:= 0 to GridCol - 1 do
begin
MemoVt[col] := TfrMemoview.Create;
MemoVt[col].Font.Name := Grid1.Font.Name;
MemoVt[col].Font.Size := Grid1.Font.Size;
MemoVt[col].Memo.Add(Grid1.Cells[col,0]);
MemoVt[col].FrameTyp := StyleType; //显示边框
TempWidth := Grid1.ColWidths[col]; //宽度与Grid中的宽度一致
MemoVt[col].SetBounds(tempLeft,top ,tempWidth,heigth);
templeft := tempLeft + tempwidth;
page.Objects.Add(MemoVt[col])
end;
end
Else
begin
top := top + heigth;
Inc(CurrRow);
TempLeft := 20;
SetLength(MemoVc,GridCol);
for col :=0 to GridCol - 1 do
begin
MemoVc[col] := TfrMemoview.Create;
MemoVc[col].Font.Name := Grid1.Font.Name;
MemoVc[col].Font.Size := Grid1.Font.Size;
MemoVc[col].Memo.Add(Grid1.Cells[col,CurrRow]);
MemoVc[col].FrameTyp := StyleType; //显示边框
TempWidth := Grid1.ColWidths[col]; //宽度与Grid中的宽度一致
MemoVc[col].SetBounds(tempLeft,top ,tempWidth,heigth);
templeft := tempLeft + tempwidth;
page.Objects.Add(MemoVc[col]);
end;
end;
if currRow >= GridRow then break;
end;
{页码}
pageV := TfrMemoview.Create;
pageV.Font.Name := '宋体';
pagev.Font.Size := 10;
pagev.FrameWidth := 2;
//pagev.FrameTyp := 24 ;
pagev.Alignment := (pagev.Alignment and $FC) + 2;//居中
pageV.Memo.Add('第'+ inttostr(I + 1) + '页 (共' + inttostr(PageCount) + '页)' );
pagev.SetBounds(0,1025,750,20);
page.Objects.Add(pageV);
end;
fr.ShowReport;
screen.Cursor := crDefault;
finally
fr.Free;
end;
end;

 

(出处:DelphiFans.com)

相关文章:
·TStringGrid中实现网格单元Hint功能
·Excel文件导入StringGrid
 → 特别推荐
 → 热点TOP10
关于我们 | 广告服务 | 发布资源 | 联系站长 Copyright 2001-2012 Delphi园地 All Rights Reserved