如何用QuickReport把StringGrid的内容打印出来?
解决方案 »
- \u65b0\u6d6a\u4f53\u80b2\ 这样的如何转成文字?
- 请问qreport如何预览超过一页纸的图片
- 关于"TChart"控件的使用问题,在线给分...
- 私有变量释放问题
- 一个关于考勤与补贴统计的查询大家都来试试,看什么方法好!
- 如何在StatusBar中显示当前form中所有控件的hint的值
- 一个DELPHI程序之精品,访问者有分!
- keydown和KeyPress事件有何不同?
- 50分....................简单问题
- 如何使对话框中的提示变为汉字?
- 请教老大们:我想用combobox将数据库中一表的指定字段内容全部显示出来,怎么做?
- 局域网内文件访问操作,大家进来讨论下
Orientation: TPrinterOrientation);
var
P, I, J, YPos, XPos, HorzSize, VertSize: Integer;
AnzSeiten, Seite, Zeilen, HeaderSize, FooterSize, ZeilenSize, FontHeight: Integer;
mmx, mmy: Extended;
Footer: string;
begin
HeaderSize := 100;
FooterSize := 200;
ZeilenSize := 36;
FontHeight := 36; Printer.Orientation := Orientation;
Printer.Title := Title;
Printer.BeginDoc;
mmx := GetDeviceCaps(Printer.Canvas.Handle, PHYSICALWIDTH) /
GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSX) * 25.4;
mmy := GetDeviceCaps(Printer.Canvas.Handle, PHYSICALHEIGHT) /
GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSY) * 25.4; VertSize := Trunc(mmy) * 10;
HorzSize := Trunc(mmx) * 10;
SetMapMode(Printer.Canvas.Handle, MM_LOMETRIC); Zeilen := (VertSize - HeaderSize - FooterSize) div ZeilenSize;
if Grid.RowCount mod Zeilen <> 0 then
AnzSeiten := Grid.RowCount div Zeilen + 1
else
AnzSeiten := Grid.RowCount div Zeilen; Seite := 1;
for P := 1 to AnzSeiten do
begin
Printer.Canvas.Font.Height := 48;
Printer.Canvas.TextOut((HorzSize div 2 - (Printer.Canvas.TextWidth(Title) div 2)),
- 20,Title);
Printer.Canvas.Pen.Width := 5;
Printer.Canvas.MoveTo(0, - HeaderSize);
Printer.Canvas.LineTo(HorzSize, - HeaderSize);
Printer.Canvas.MoveTo(0, - VertSize + FooterSize);
Printer.Canvas.LineTo(HorzSize, - VertSize + FooterSize);
Printer.Canvas.Font.Height := 36;
Footer := 'Seite: ' + IntToStr(Seite) + ' von ' + IntToStr(AnzSeiten);
Printer.Canvas.TextOut((HorzSize div 2 - (Printer.Canvas.TextWidth(Footer) div 2)),
- VertSize + 150,Footer);
Printer.Canvas.Font.Height := FontHeight;
YPos := HeaderSize + 10;
for I := 1 to Zeilen do
begin
if Grid.RowCount >= I + (Seite - 1) * Zeilen then
begin
XPos := 0;
for J := 0 to Grid.ColCount - 1 do
begin
Printer.Canvas.TextOut(XPos, - YPos,
Grid.Cells[J, I + (Seite - 1) * Zeilen - 1]);
XPos := XPos + Grid.ColWidths[J] * 3;
end;
YPos := YPos + ZeilenSize;
end;
end;
Inc(Seite);
if Seite <= AnzSeiten then Printer.NewPage;
end;
Printer.EndDoc;
end;
var
i : integer;QuickRep1的onBeforePrint事件: i:=0;QuickRep1的onNeedData事件:
MoreData := (i<=StringGrid1.RowCount - 1);
if MoreData then
begin
QRLabel1.Caption:=StringGrid1.Cells[0,i];
QRLabel2.Caption:=StringGrid1.Cells[1,i];
QRLabel3.Caption:=StringGrid1.Cells[2,i];
QRLabel4.Caption:=StringGrid1.Cells[3,i];
QRLabel5.Caption:=StringGrid1.Cells[4,i];
QRLabel6.Caption:=StringGrid1.Cells[5,i];
QRLabel12.Caption:=StringGrid1.Cells[6,i];
QRLabel13.Caption:=StringGrid1.Cells[7,i];
......//看你需要 Inc(i);
end;
http://www.2ccc.com/dl.asp?url=http://downloads.2ccc.com/vcl/grids/EhLib.v3.4.hh.by.Netrobo.rar它自代这个功能,还有更好用的呢
TQuickRep的OnNeedData事件,注意思:不要指定任何数据源!procedure TReportPreviewForm.ListRepNeedData(Sender: TObject;
var MoreData: Boolean);
begin
MoreData:=(I<=MainForm.StringGrid1.RowCount-1);
IDLabel.Caption:=Trim(MainForm.StringGrid1.Cells[0,i]);
AreaLabel.Caption:=Trim(MainForm.StringGrid1.Cells[1,i]);
ItemNameLabel.Caption:=Trim(MainForm.StringGrid1.Cells[2,i]);
if Trim(MainForm.StringGrid1.Cells[1,i])='' then
ItemNameLabel.Alignment:=taRightJustify
else
ItemNameLabel.Alignment:=taLeftJustify;
SortNameLabel.Caption:=Trim(MainForm.StringGrid1.Cells[3,i]);
PinPaiLabel.Caption:=Trim(MainForm.StringGrid1.Cells[4,i]);
DanWeiLabel.Caption:=Trim(MainForm.StringGrid1.Cells[5,i]);
PriceLabel.Caption:=Trim(MainForm.StringGrid1.Cells[6,i]);
ICountLabel.Caption:=Trim(MainForm.StringGrid1.Cells[7,i]);
MoneyLabel.Caption:=Trim(MainForm.StringGrid1.Cells[8,i]);
QRShape201.Brush.Color:=MainForm.StringGrid1.Colors[8,i];
if (Trim(MainForm.ItemList.Cells[1,i])='')and(i<>MainForm.StringGrid1.RowCount-1) then
QRShape1.Brush.Color:=clBlue; //变色;
i:=i+1; //I为全局变量,初值为:0;
end;