请问一下,如何打印DBGrid中所有的数据记录? 在程序中如何把DBGrid中所显示的数据记录全部打印出来? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 连接一个自动报表生成的report的,就可以打印了 rxlib控件,里边有一个功能差不多的控件好像支持打印, 试试这个:procedure TData.PrintDbGrid(DataSet: TDataSet; DbGrid: TDbGrid; Title: String);var PointX,PointY:integer; ScreenX:integer; i,lx,ly:integer; px1,py1,px2,py2:integer; RowPerPage,RowPrinted:integer; ScaleX:Real; THeight:integer; TitleWidth:integer; SumWidth:integer; PageCount:integer; SpaceX,SpaceY:integer; RowCount:integer;begin PointX := Round(GetDeviceCaps(Printer.Handle, LOGPIXELSX) / 2.54); PointY := Round(GetDeviceCaps(Printer.Handle, LOGPIXELSY) / 2.54); ScreenX:= Round(Screen.PixelsPerInch / 2.54); ScaleX := PointX / ScreenX; RowPrinted := 0; SumWidth := 0; Printer.BeginDoc; With Printer.Canvas do begin DataSet.DisableControls; DataSet.First; THeight := Round(TextHeight('ÎÒ') * 2); //É趨ÿÐи߶ÈΪ×Ö·û¸ßµÄ1.5±¶ SpaceY := Round(TextHeight('ÎÒ') / 4); SpaceX := Round(TextWidth('ÎÒ') / 4); RowPerpage := Round((Printer.PageHeight - 3 * PointY) / THeight); //ÉÏϱßÔµ¸÷2ÀåÃ× ly := 2 * PointY; PageCount := 0; Pen.Width := Pen.Width * 4; while not DataSet.Eof do begin if (RowPrinted = RowPerPage) or (RowPrinted = 0) then begin if RowPrinted <> 0 then Printer.NewPage; RowPrinted := 0; PageCount := PageCount + 1; Font.Name := 'ËÎÌå'; Font.size := 16; Font.Style := Font.Style + [fsBold]; lx := Round((Printer.PageWidth - TextWidth(Title)) / 2); ly := 2 * PointY; TextOut(lx, ly, Title); Font.Size := 11; Font.Style := Font.Style - [fsBold]; lx := Printer.PageWidth - 5 * PointX; ly := Round(2 * PointY + 0.8 * PointY); if RowPerPage * PageCount > DataSet.RecordCount then RowCount := DataSet.RecordCount else RowCount := RowPerPage * PageCount; TextOut(lx, ly, 'µÚ' + IntToStr(RowPerPage * (PageCount - 1) + 1) + '-' + IntToStr(RowCount) + 'Ìõ£¬¹²' + IntToStr(DataSet.RecordCount) + 'Ìõ'); lx := 2 * PointX; ly := ly + THeight * 2; py1:= ly - SpaceY; if RowCount = DataSet.RecordCount then py2 := py1 + THeight * (RowCount - RowPerPage * (PageCount - 1) + 1) else py2 := py1 + THeight * (RowPerPage + 1); SumWidth := lx; for i:=0 to DBGrid.Columns.Count-1 do begin px1 := SumWidth - SpaceX; px2 := SumWidth; MoveTo(px1, py1); LineTo(px2, py2); TitleWidth := TextWidth(DBGrid.Columns[i].Title.Caption); lx := Round(SumWidth + (DBGrid.Columns[i].width * scaleX-titleWidth) / 2); TextOut(lx, ly, DBGrid.Columns[i].Title.Caption); SumWidth := Round(SumWidth + DBGrid.Columns[i].width * scaleX) + SpaceX * 2; end; px1 := SumWidth; //»­×îºóÒ»ÌõÊúÏß px2 := SumWidth; MoveTo(px1, py1); LineTo(px2, py2); px1 := 2 * PointX; //»­µÚÒ»ÌõºáÏß px2 := SumWidth; py1 := ly - SpaceY; py2 := ly - SpaceY; MoveTo(px1, py1); LineTo(px2, py2); py1 := py1 + THeight; py2 := py2 + THeight; MoveTo(px1, py1); LineTo(px2, py2); end; lx := 2 * PointX; ly := ly + THeight; px1:= lx; px2:= SumWidth; py1:= ly - SpaceY + THeight; py2:= ly - SpaceY + THeight; MoveTo(px1, py1); LineTo(px2, py2); for i := 0 to DBGrid.Columns.Count - 1 do begin TextOut(lx, ly, Trim(DataSet.FieldByname(DBGrid.Columns[i].Fieldname).AsString)); lx := Round(lx + DBGrid.Columns[i].width * ScaleX + SpaceX * 2); end; RowPrinted := RowPrinted + 1; DataSet.next; end; DataSet.First; DataSet.EnableControls; end; printer.EndDoc;end; 可以用delphi自带的报表控件,DELPHI6中是QuickReport,7中是Rave.也可以找其他第三方控件,如FastReport. 求一元线性趋势方程算法 一个简化的FAT16文件系统. 请问怎样修改Tstringlist第一行的数据啊? 求救!!! 关于激活已经存在的子窗口的奇怪问题。 实在是不明白result的作用!! 关于存取服务器目录下的文件的问题。 我用动态数组创建了一批的Label,我想对这些动态创建的控件进行事件的处理,比如用鼠标拉动它们进行移动?请问各位我应该怎么做? 使用Delphi是否可以嵌入c语言来对惠普的仪器接口进行编程? 请教在数据库的表格里面插入指定位置记录的问题 删除一条数据遇到个问题,在线等 急急.在线等待.高手帮忙
procedure TData.PrintDbGrid(DataSet: TDataSet; DbGrid: TDbGrid;
Title: String);
var
PointX,PointY:integer;
ScreenX:integer;
i,lx,ly:integer;
px1,py1,px2,py2:integer;
RowPerPage,RowPrinted:integer;
ScaleX:Real;
THeight:integer;
TitleWidth:integer;
SumWidth:integer;
PageCount:integer;
SpaceX,SpaceY:integer;
RowCount:integer;
begin
PointX := Round(GetDeviceCaps(Printer.Handle, LOGPIXELSX) / 2.54);
PointY := Round(GetDeviceCaps(Printer.Handle, LOGPIXELSY) / 2.54);
ScreenX:= Round(Screen.PixelsPerInch / 2.54);
ScaleX := PointX / ScreenX;
RowPrinted := 0;
SumWidth := 0; Printer.BeginDoc; With Printer.Canvas do
begin
DataSet.DisableControls;
DataSet.First; THeight := Round(TextHeight('ÎÒ') * 2); //É趨ÿÐи߶ÈΪ×Ö·û¸ßµÄ1.5±¶
SpaceY := Round(TextHeight('ÎÒ') / 4);
SpaceX := Round(TextWidth('ÎÒ') / 4);
RowPerpage := Round((Printer.PageHeight - 3 * PointY) / THeight); //ÉÏϱßÔµ¸÷2ÀåÃ×
ly := 2 * PointY;
PageCount := 0;
Pen.Width := Pen.Width * 4; while not DataSet.Eof do
begin
if (RowPrinted = RowPerPage) or (RowPrinted = 0) then
begin
if RowPrinted <> 0 then
Printer.NewPage;
RowPrinted := 0;
PageCount := PageCount + 1;
Font.Name := 'ËÎÌå';
Font.size := 16;
Font.Style := Font.Style + [fsBold];
lx := Round((Printer.PageWidth - TextWidth(Title)) / 2);
ly := 2 * PointY;
TextOut(lx, ly, Title);
Font.Size := 11;
Font.Style := Font.Style - [fsBold];
lx := Printer.PageWidth - 5 * PointX;
ly := Round(2 * PointY + 0.8 * PointY);
if RowPerPage * PageCount > DataSet.RecordCount then
RowCount := DataSet.RecordCount
else
RowCount := RowPerPage * PageCount; TextOut(lx, ly,
'µÚ' + IntToStr(RowPerPage * (PageCount - 1) + 1)
+ '-' + IntToStr(RowCount) + 'Ìõ£¬¹²'
+ IntToStr(DataSet.RecordCount) + 'Ìõ'); lx := 2 * PointX;
ly := ly + THeight * 2;
py1:= ly - SpaceY;
if RowCount = DataSet.RecordCount then
py2 := py1 + THeight * (RowCount - RowPerPage * (PageCount - 1) + 1)
else
py2 := py1 + THeight * (RowPerPage + 1);
SumWidth := lx;
for i:=0 to DBGrid.Columns.Count-1 do
begin
px1 := SumWidth - SpaceX;
px2 := SumWidth;
MoveTo(px1, py1);
LineTo(px2, py2);
TitleWidth := TextWidth(DBGrid.Columns[i].Title.Caption);
lx := Round(SumWidth + (DBGrid.Columns[i].width * scaleX-titleWidth) / 2);
TextOut(lx, ly, DBGrid.Columns[i].Title.Caption);
SumWidth := Round(SumWidth + DBGrid.Columns[i].width * scaleX) + SpaceX * 2;
end; px1 := SumWidth; //»­×îºóÒ»ÌõÊúÏß
px2 := SumWidth;
MoveTo(px1, py1);
LineTo(px2, py2);
px1 := 2 * PointX; //»­µÚÒ»ÌõºáÏß
px2 := SumWidth;
py1 := ly - SpaceY;
py2 := ly - SpaceY;
MoveTo(px1, py1);
LineTo(px2, py2);
py1 := py1 + THeight;
py2 := py2 + THeight;
MoveTo(px1, py1);
LineTo(px2, py2);
end; lx := 2 * PointX;
ly := ly + THeight;
px1:= lx;
px2:= SumWidth;
py1:= ly - SpaceY + THeight;
py2:= ly - SpaceY + THeight;
MoveTo(px1, py1);
LineTo(px2, py2);
for i := 0 to DBGrid.Columns.Count - 1 do
begin
TextOut(lx, ly, Trim(DataSet.FieldByname(DBGrid.Columns[i].Fieldname).AsString));
lx := Round(lx + DBGrid.Columns[i].width * ScaleX + SpaceX * 2);
end;
RowPrinted := RowPrinted + 1;
DataSet.next;
end;
DataSet.First;
DataSet.EnableControls;
end;
printer.EndDoc;end;
也可以找其他第三方控件,如FastReport.