用ReportBuilder, 打印列数随机变化的StringGrid, 要怎么处理?(200)

  • 主题发起人 主题发起人 lishding
  • 开始时间 开始时间
L

lishding

Unregistered / Unconfirmed
GUEST, unregistred user!
现有一个 StringGrid 用来显示数据它的列根据用户自己的意愿显示和不显示哪些列,现在要用 ReportBuilder 做报表来打印此 StringGrid所显示出来的数据;刚开始想的是用 导出图片再导入到报表控件里的方式打印,但打印出来的效果是分辩率不对,字好像是bmp放大了很多倍的那种效果。请问大家有什么办法解决 或别的好用的方法。打印时的代码如下: Cav:=TCanvas.Create;
Cav.Handle:=GetDC(P_Grid_Cacles.Handle);
// P_Grid_Cacles 是放置StringGrid的Panel Bmp:=TBitmap.Create;
StBmp:=TBitmap.Create;
Bmp.Height:=Cav.ClipRect.Bottom;
Bmp.Width:=Cav.ClipRect.Right;
Bmp.Canvas.CopyRect(Panel1.ClientRect,Cav,Panel1.ClientRect);
//截图 Bmp.SaveToFile('temp.bmp');
Cav.Destroy;
Bmp.Destroy;
ppImage2.Picture.LoadFromFile('temp.bmp');
ppReport1.Print;
 
我倒是 用 fastreport 做过 ReportBuilder 我没用
 
hfghfghfg: 请教 你是怎么处理的? 能讲一下思路吗?
 
procedure TfrmDataset.printDataset(DataSet: TDataSet;
colLen: array of Integer;
coltitle, coldata: array of string);var tmpfn: string;
begin
tmpfn := GetTempPathFileName();
TADODataSet(DataSet).SaveToFile(tmpfn);
ADODataSet.LoadFromFile(tmpfn);
makereport_byarray(frReport2, self.Font, colLen, coltitle, coldata);
frReport2.ShowReport;
end;
procedure makereport_byarray(frRpt: TfrReport;
font: TFont;
colLen: array of Integer;
coltitle, coldata: array of string);var i: integer;
strlen: array of integer;
titleview: TfrMemoView;
memoview: TfrMemoView;
MasterBand: TfrBandView;
ColumnHeader: TfrBandView;
x, y1, y2, w, sum_len, sum_i, x_i, x_i_old: integer;
s: string;
begin
do
cMode := dmDesigning;
SetLength(strlen, length(coltitle));
if length(colLen) = length(coltitle) then
begin
for i := 0 to high(strlen)do
strlen := colLen;
end else
begin
for i := 0 to high(strlen)do
strlen := 0;
for i := 0 to high(strlen)do
begin
s := '';
s := coltitle;
strlen := length(s);
if strlen = 0 then
strlen := 1;
end;
end;
titleview := TfrMemoView(frRpt.Pages[0].FindObject('Memo1'));
MasterBand := TfrBandView(frRpt.Pages[0].FindObject('MasterData1'));
ColumnHeader := TfrBandView(frRpt.Pages[0].FindObject('ColumnHeader1'));
x := titleview.Prop['Left'];
w := titleview.Prop['width'];
sum_len := 0;
for i := 0 to high(strlen)do
inc(sum_len, strlen);
sum_i := 0;
for i := 0 to high(strlen)do
begin
inc(sum_i, strlen);
x_i := round(sum_i * w / sum_len);
if i = 0 then
strlen := x_i else
strlen := x_i - x_i_old;
x_i_old := x_i;
end;
x := titleview.Prop['Left'];
y1 := ColumnHeader.Prop['top'];
y2 := y1 + ColumnHeader.Prop['height'];
y1 := y2 - MasterBand.Prop['height'];
for i := 0 to high(strlen)do
begin
memoview := TfrMemoView.Create;
memoview.Prop['top'] := y1;
memoview.Prop['height'] := y2 - y1;
memoview.Prop['Left'] := x;
memoview.Prop['width'] := strlen;
memoview.Prop['textonly'] := true;
memoview.Prop['ALIGNMENT'] := 10;
memoview.FrameTyp := 15;
s := '';
s := coltitle;
memoview.Memo.Text := s;
memoview.Font.Assign(font);
frRpt.Pages[0].Objects.Add(memoview);
inc(x, strlen);
end;
x := titleview.Prop['Left'];
y1 := MasterBand.Prop['top'];
y2 := y1 + MasterBand.Prop['height'];
for i := 0 to high(strlen)do
begin
memoview := TfrMemoView.Create;
memoview.Prop['top'] := y1;
memoview.Prop['height'] := y2 - y1;
memoview.Prop['Left'] := x;
memoview.Prop['width'] := strlen;
memoview.Prop['ALIGNMENT'] := 10;
memoview.FrameTyp := 15;
memoview.Memo.Text := coldata;
memoview.Font.Assign(font);
frRpt.Pages[0].Objects.Add(memoview);
inc(x, strlen);
end;
setlength(strlen, 0);
end;
 
结束了,还是没用截图了,用笨点的方法手工调位置了。
 

Similar threads

后退
顶部