我以一个rmreport和dbgrid的例,打dbgrid显示的数据,不打印dbgrid隐藏的数据 function rmprint(inititle:string;RMReportName: TRMReport;GridViewName: TcxGridDBTableView;DateFooter1:string='';DateFooter2:string='';DateFooter3:string='';TTitle:string='';Title1:string='';title2:string='';title3:string='';SumNfooter1:string='';SumNfooter2:string='';SumNfooter3:string='';Sumfooter1:string='';Sumfooter2:string='';Sumfooter3:string=''):boolean; var tt:TRMMemoview; lBandReportTitle: TRMBandReportTitle; lMasterDataBand: TRMBandMasterData; lPage: TRMReportPage; tPageFooter:TRMBandPageFooter; tPageHeader:TRMBandPageHeader; tBandFooter:TRMBandFooter; i,ii,ileft:integer; exout:boolean; inifilepath:string; hr_dbgrid:Tinifile; begin inifilepath:=ExtractFilePath(application.ExeName)+'hr_dbgrid.ini'; hr_dbgrid:=Tinifile.Create(inifilepath); try screen.Cursor:=crSQLWait; with RMReportName do begin DoublePass:=true; ReportInfo.Title:=TTitle; Pages.Clear; ColorPrint:=false; end; lPage := RMReportName.Pages.AddReportPage; // create page lBandReportTitle:= TRMBandReportTitle.Create; lBandReportTitle.ParentPage:=lpage; lBandReportTitle.SetBounds(10,0,697,60); tt := TRMMemoview.Create; // 标题 with tt do begin ParentPage := lPage; SetspBounds(280, 0, 200, 20); AutoWidth:=true; BandAlign:=rmbaCenter; HAlign:=rmhCenter; BottomFrame.Visible:=true; Font.Style:=[fsBold]; //Font.Color:=$00981812; Font.Size:=12; Memo.Add(TTitle); end; tt := TRMMemoview.Create; // 标题单1 with tt do begin ParentPage := lPage; SetspBounds(0, 30, 300, 20); AutoWidth:=true; HAlign:=rmhCenter; Memo.Add(Title1); end; tt:= TRMMemoview.Create; // 标题单2 with tt do begin ParentPage := lPage; SetspBounds(200, 30, 300, 20); AutoWidth:=true; HAlign:=rmhCenter; Memo.Add(Title2); end; tt := TRMMemoview.Create; // 标题单3 with tt do begin ParentPage := lPage; SetspBounds(400, 30, 300, 20); AutoWidth:=true; HAlign:=rmhCenter; Memo.Add(Title3); end; tPageHeader:=TRMBandPageHeader.Create;//表头 tPageHeader.ParentPage:= lPage; tPageHeader.SetspBounds(20, 60, 200, 20); ii:=0; ileft:=1; exout:=false; for i:=0 to GridViewName.ColumnCount-1 do begin //if GridViewName.Columns[i].Visible then if hr_dbgrid.ReadBool(inititle,GridViewName.Columns[i].Caption+'.P',true) then begin tt := TRMMemoview.Create; // create data field with tt do begin ParentPage := lPage; if ii+GridViewName.Columns[i].Width>680 then if exout then begin SetspBounds(ii, 60, GridViewName.Columns[i].Width, 20); Visible:=false; end else begin SetspBounds(ii, 60, 680-ii, 20); exout:=true; end else SetspBounds(ii, 60, GridViewName.Columns[i].Width, 20); Font.Style:=[fsBold]; HAlign:=rmhCenter; VAlign:=rmvCenter; Memo.Add(GridViewName.Columns[i].Caption); LeftFrame.Visible := True; TopFrame.Visible := True; if exout then RightFrame.Visible := false else RightFrame.Visible := true; BottomFrame.Visible := True; TopFrame.spWidth:=2; if ileft=1 then//设置左边 begin LeftFrame.spWidth:=2; ileft:=0; end; ii:=ii+round(tt.Width); end; end; end;
tt.RightFrame.spWidth:=2;//设置右边 lMasterDataBand := TRMBandMasterData.Create; lMasterDataBand.ParentPage := lPage; lMasterDataBand.SetspBounds(20, 80, 200, 20); lMasterDataBand.DataSetName := 'RMDBDataSet1'; ii:=0; ileft:=1; exout:=false; for i:=0 to GridViewName.ColumnCount-1 do begin if hr_dbgrid.ReadBool(inititle,GridViewName.Columns[i].Caption+'.P',true) then begin tt := TRMMemoview.Create; // create data field with tt do begin ParentPage := lPage; //SetspBounds(ii, 80, GridViewName.Columns[i].Width, 20); if ii+GridViewName.Columns[i].Width>680 then if exout then begin SetspBounds(ii, 80, GridViewName.Columns[i].Width, 20); Visible:=false; end else begin SetspBounds(ii, 80, 680-ii, 20); exout:=true; end else SetspBounds(ii, 80, GridViewName.Columns[i].Width, 20); HideZeros:=false; VAlign:=rmvCenter; Memo.Add('[RMDBDataSet1."'+GridViewName.Columns[i].DataBinding.FieldName+'"]'); LeftFrame.Visible := True; TopFrame.Visible := True; if exout then RightFrame.Visible := false else RightFrame.Visible := true; BottomFrame.Visible := True; if ileft=1 then//设置左边 begin LeftFrame.spWidth:=2; ileft:=0; end; ii:=ii+round(tt.Width); end; end; end; tt.RightFrame.spWidth:=2;//设置右边 tBandFooter:=TRMBandFooter.Create;//数据脚注 tBandfooter.ParentPage:=lPage; tBandFooter.SetBounds(10,100,697,100); ii:=0; ileft:=1; exout:=false; for i:=0 to GridViewName.ColumnCount-1 do begin if hr_dbgrid.ReadBool(inititle,GridViewName.Columns[i].Caption+'.P',true) then begin tt := TRMMemoview.Create; // create data field with tt do begin ParentPage := lPage; //SetspBounds(ii, 100, GridViewName.Columns[i].Width, 20); if ii+GridViewName.Columns[i].Width>680 then if exout then begin SetspBounds(ii, 100, GridViewName.Columns[i].Width, 20); Visible:=false; end else begin SetspBounds(ii, 100, 680-ii, 20); exout:=true; end else SetspBounds(ii, 100, GridViewName.Columns[i].Width, 20); //font.Color:=clred; HAlign:=rmhCenter; VAlign:=rmvCenter; LeftFrame.Visible := True; TopFrame.Visible := True; if exout then RightFrame.Visible := false else RightFrame.Visible := true; BottomFrame.Visible := True; if ileft=1 then//设置左边 begin LeftFrame.spWidth:=2; ileft:=0; Memo.Add('合计'); Font.Style:=[fsBold]; end; BottomFrame.spWidth:=2; if SumNfooter1=GridViewName.Columns[i].DataBinding.FieldName then Memo.Add(Sumfooter1); if SumNfooter2=GridViewName.Columns[i].DataBinding.FieldName then Memo.Add(Sumfooter2); if SumNfooter3=GridViewName.Columns[i].DataBinding.FieldName then Memo.Add(Sumfooter3); ii:=ii+round(tt.Width); end; end; end; tt.RightFrame.spWidth:=2; tt:= TRMMemoview.Create; // 数据脚注1 with tt do begin ParentPage := lPage; SetspBounds(0, 140, 200, 20); AutoWidth:=true; HAlign:=rmhCenter; Memo.Add(DateFooter1); end; tt:= TRMMemoview.Create; // 数据脚注2 with tt do begin ParentPage := lPage; SetspBounds(0, 160, 200, 20); AutoWidth:=true; HAlign:=rmhCenter; Memo.Add(DateFooter2); end; tt:= TRMMemoview.Create; // 数据脚注3 with tt do begin ParentPage := lPage; SetspBounds(0, 180, 200, 20); AutoWidth:=true; HAlign:=rmhCenter; Memo.Add(DateFooter3); end; tPageFooter:=TRMBandPageFooter.Create;//页脚 tPageFooter.ParentPage:=lPage; tPageFooter.SetBounds(10,200,697,20); tt := TRMMemoview.Create; // create data field tt.ParentPage := lPage; tt.SetspBounds(0, 200, 150, 20); tt.AutoWidth:=true; tt.BandAlign:=rmbaCenter; tt.HAlign:=rmhCenter; tt.VAlign:=rmvCenter; tt.Memo.Add('当前第【[_RM_Page]】页--共【[_RM_TotalPages]】页'); finally screen.Cursor:=crDefault; hr_dbgrid.Free; end; result:=true; end;
function rmprint(inititle:string;RMReportName: TRMReport;GridViewName: TcxGridDBTableView;DateFooter1:string='';DateFooter2:string='';DateFooter3:string='';TTitle:string='';Title1:string='';title2:string='';title3:string='';SumNfooter1:string='';SumNfooter2:string='';SumNfooter3:string='';Sumfooter1:string='';Sumfooter2:string='';Sumfooter3:string=''):boolean;
var
tt:TRMMemoview;
lBandReportTitle: TRMBandReportTitle;
lMasterDataBand: TRMBandMasterData;
lPage: TRMReportPage;
tPageFooter:TRMBandPageFooter;
tPageHeader:TRMBandPageHeader;
tBandFooter:TRMBandFooter;
i,ii,ileft:integer;
exout:boolean;
inifilepath:string;
hr_dbgrid:Tinifile;
begin
inifilepath:=ExtractFilePath(application.ExeName)+'hr_dbgrid.ini';
hr_dbgrid:=Tinifile.Create(inifilepath);
try
screen.Cursor:=crSQLWait;
with RMReportName do
begin
DoublePass:=true;
ReportInfo.Title:=TTitle;
Pages.Clear;
ColorPrint:=false;
end;
lPage := RMReportName.Pages.AddReportPage; // create page
lBandReportTitle:= TRMBandReportTitle.Create;
lBandReportTitle.ParentPage:=lpage;
lBandReportTitle.SetBounds(10,0,697,60);
tt := TRMMemoview.Create; // 标题
with tt do
begin
ParentPage := lPage;
SetspBounds(280, 0, 200, 20);
AutoWidth:=true;
BandAlign:=rmbaCenter;
HAlign:=rmhCenter;
BottomFrame.Visible:=true;
Font.Style:=[fsBold];
//Font.Color:=$00981812;
Font.Size:=12;
Memo.Add(TTitle);
end; tt := TRMMemoview.Create; // 标题单1
with tt do
begin
ParentPage := lPage;
SetspBounds(0, 30, 300, 20);
AutoWidth:=true;
HAlign:=rmhCenter;
Memo.Add(Title1);
end;
tt:= TRMMemoview.Create; // 标题单2
with tt do
begin
ParentPage := lPage;
SetspBounds(200, 30, 300, 20);
AutoWidth:=true;
HAlign:=rmhCenter;
Memo.Add(Title2);
end;
tt := TRMMemoview.Create; // 标题单3
with tt do
begin
ParentPage := lPage;
SetspBounds(400, 30, 300, 20);
AutoWidth:=true;
HAlign:=rmhCenter;
Memo.Add(Title3);
end;
tPageHeader:=TRMBandPageHeader.Create;//表头
tPageHeader.ParentPage:= lPage;
tPageHeader.SetspBounds(20, 60, 200, 20);
ii:=0;
ileft:=1;
exout:=false;
for i:=0 to GridViewName.ColumnCount-1 do
begin
//if GridViewName.Columns[i].Visible then
if hr_dbgrid.ReadBool(inititle,GridViewName.Columns[i].Caption+'.P',true) then
begin
tt := TRMMemoview.Create; // create data field
with tt do
begin
ParentPage := lPage;
if ii+GridViewName.Columns[i].Width>680 then
if exout then
begin
SetspBounds(ii, 60, GridViewName.Columns[i].Width, 20);
Visible:=false;
end
else
begin
SetspBounds(ii, 60, 680-ii, 20);
exout:=true;
end
else
SetspBounds(ii, 60, GridViewName.Columns[i].Width, 20);
Font.Style:=[fsBold];
HAlign:=rmhCenter;
VAlign:=rmvCenter;
Memo.Add(GridViewName.Columns[i].Caption);
LeftFrame.Visible := True;
TopFrame.Visible := True;
if exout then
RightFrame.Visible := false
else
RightFrame.Visible := true;
BottomFrame.Visible := True;
TopFrame.spWidth:=2;
if ileft=1 then//设置左边
begin
LeftFrame.spWidth:=2;
ileft:=0;
end;
ii:=ii+round(tt.Width);
end;
end;
end;
lMasterDataBand := TRMBandMasterData.Create;
lMasterDataBand.ParentPage := lPage;
lMasterDataBand.SetspBounds(20, 80, 200, 20);
lMasterDataBand.DataSetName := 'RMDBDataSet1';
ii:=0;
ileft:=1;
exout:=false;
for i:=0 to GridViewName.ColumnCount-1 do
begin
if hr_dbgrid.ReadBool(inititle,GridViewName.Columns[i].Caption+'.P',true) then
begin
tt := TRMMemoview.Create; // create data field
with tt do
begin
ParentPage := lPage;
//SetspBounds(ii, 80, GridViewName.Columns[i].Width, 20); if ii+GridViewName.Columns[i].Width>680 then
if exout then
begin
SetspBounds(ii, 80, GridViewName.Columns[i].Width, 20);
Visible:=false;
end
else
begin
SetspBounds(ii, 80, 680-ii, 20);
exout:=true;
end
else
SetspBounds(ii, 80, GridViewName.Columns[i].Width, 20); HideZeros:=false;
VAlign:=rmvCenter;
Memo.Add('[RMDBDataSet1."'+GridViewName.Columns[i].DataBinding.FieldName+'"]');
LeftFrame.Visible := True;
TopFrame.Visible := True;
if exout then
RightFrame.Visible := false
else
RightFrame.Visible := true;
BottomFrame.Visible := True;
if ileft=1 then//设置左边
begin
LeftFrame.spWidth:=2;
ileft:=0;
end;
ii:=ii+round(tt.Width);
end; end;
end;
tt.RightFrame.spWidth:=2;//设置右边
tBandFooter:=TRMBandFooter.Create;//数据脚注
tBandfooter.ParentPage:=lPage;
tBandFooter.SetBounds(10,100,697,100);
ii:=0;
ileft:=1;
exout:=false;
for i:=0 to GridViewName.ColumnCount-1 do
begin
if hr_dbgrid.ReadBool(inititle,GridViewName.Columns[i].Caption+'.P',true) then
begin
tt := TRMMemoview.Create; // create data field
with tt do
begin
ParentPage := lPage;
//SetspBounds(ii, 100, GridViewName.Columns[i].Width, 20);
if ii+GridViewName.Columns[i].Width>680 then
if exout then
begin
SetspBounds(ii, 100, GridViewName.Columns[i].Width, 20);
Visible:=false;
end
else
begin
SetspBounds(ii, 100, 680-ii, 20);
exout:=true;
end
else
SetspBounds(ii, 100, GridViewName.Columns[i].Width, 20);
//font.Color:=clred;
HAlign:=rmhCenter;
VAlign:=rmvCenter;
LeftFrame.Visible := True;
TopFrame.Visible := True;
if exout then
RightFrame.Visible := false
else
RightFrame.Visible := true;
BottomFrame.Visible := True;
if ileft=1 then//设置左边
begin
LeftFrame.spWidth:=2;
ileft:=0;
Memo.Add('合计');
Font.Style:=[fsBold];
end;
BottomFrame.spWidth:=2;
if SumNfooter1=GridViewName.Columns[i].DataBinding.FieldName then
Memo.Add(Sumfooter1);
if SumNfooter2=GridViewName.Columns[i].DataBinding.FieldName then
Memo.Add(Sumfooter2);
if SumNfooter3=GridViewName.Columns[i].DataBinding.FieldName then
Memo.Add(Sumfooter3);
ii:=ii+round(tt.Width);
end;
end;
end;
tt.RightFrame.spWidth:=2;
tt:= TRMMemoview.Create; // 数据脚注1
with tt do
begin
ParentPage := lPage;
SetspBounds(0, 140, 200, 20);
AutoWidth:=true;
HAlign:=rmhCenter;
Memo.Add(DateFooter1);
end;
tt:= TRMMemoview.Create; // 数据脚注2
with tt do
begin
ParentPage := lPage;
SetspBounds(0, 160, 200, 20);
AutoWidth:=true;
HAlign:=rmhCenter;
Memo.Add(DateFooter2);
end;
tt:= TRMMemoview.Create; // 数据脚注3
with tt do
begin
ParentPage := lPage;
SetspBounds(0, 180, 200, 20);
AutoWidth:=true;
HAlign:=rmhCenter;
Memo.Add(DateFooter3);
end;
tPageFooter:=TRMBandPageFooter.Create;//页脚
tPageFooter.ParentPage:=lPage;
tPageFooter.SetBounds(10,200,697,20);
tt := TRMMemoview.Create; // create data field
tt.ParentPage := lPage;
tt.SetspBounds(0, 200, 150, 20);
tt.AutoWidth:=true;
tt.BandAlign:=rmbaCenter;
tt.HAlign:=rmhCenter;
tt.VAlign:=rmvCenter;
tt.Memo.Add('当前第【[_RM_Page]】页--共【[_RM_TotalPages]】页');
finally
screen.Cursor:=crDefault;
hr_dbgrid.Free;
end;
result:=true;
end;
可以卖给你们公司,非常成熟,做了好几年的自定义报表系统
[email protected]