dynamic create with the dbgrid column , it easy only taken time to judge the position , i write a component , only use it but too simpe,if you want i send you!
To TFPE: [email protected] qiandeng: 我也知道是这样做,但是不知道怎样去定位画线的位置x,y,表格有宽,高,怎样去很好的控制,要画行表格,要画列表格。
E文好的仔细读读,是在一个E文网站上找到的 Creating a Quick Report layout at runtime to print DBGrid's contents First make a new form, name it as TGridReport and drop a TQuickRep on it. Rename you QuickRep to GridRep. Then make a Preview that receives a DBGrid as parameter, just like this: procedure TGridReport.Preview(Grid: TDBGrid); var i, CurrentLeft, CurrentTop : integer; BMark: TBook; begin GridRep.Dataset:=Grid.DataSource.DataSet; if not GridRep.Bands.HasColumnHeader then GridRep.Bands.HasColumnHeader:=true; if not GridRep.Bands.HasDetail then GridRep.Bands.HasDetail:=true; GridRep.Bands.ColumnHeaderBand.Height:=Abs(Grid.TitleFont.Height) + 10; GridRep.Bands.DetailBand.Height:=Abs(Grid.Font.Height) + 10; CurrentLeft := 12; CurrentTop := 6; {Record where the user stopped in the DBGrid} BMark:=Grid.DataSource.DataSet.GetBook; {Don't let the grid flicker while the report is running} Grid.DataSource.DataSet.DisableControls; try for i:=0 to Grid.FieldCount - 1 do begin if (CurrentLeft + Canvas.TextWidth(Grid.Columns[i].Title.Caption)) > (GridRep.Bands.ColumnHeaderBand.Width) then begin CurrentLeft := 12; CurrentTop := CurrentTop + Canvas.TextHeight('A') + 6; GridRep.Bands.ColumnHeaderBand.Height := GridRep.Bands.ColumnHeaderBand.Height + (Canvas.TextHeight('A') + 10); GridRep.Bands.DetailBand.Height := GridRep.Bands.DetailBand.Height + (Canvas.TextHeight('A') + 10); end; {Create Header with QRLabels} with TQRLabel.Create(GridRep.Bands.ColumnHeaderBand) do begin Parent := GridRep.Bands.ColumnHeaderBand; Color := GridRep.Bands.ColumnHeaderBand.Color; Left := CurrentLeft; Top := CurrentTop; Caption:=Grid.Columns[i].Title.Caption; end; {Create Detail with QRDBText} with TQRDbText.Create(GridRep.Bands.DetailBand) do begin Parent := GridRep.Bands.DetailBand; Color := GridRep.Bands.DetailBand.Color; Left := CurrentLeft; Top := CurrentTop; Alignment:=Grid.Columns[i].Alignment; AutoSize:=false; AutoStretch:=true; Width:=Grid.Columns[i].Width; Dataset:=GridRep.Dataset; DataField:=Grid.Fields[i].FieldName; CurrentLeft:=CurrentLeft + (Grid.Columns[i].Width) + 15; end; end; lblPage.Left := bdTitle.Width - lblPage.Width - 10; lblDate.Left := bdTitle.Width - lblDate.Width - 10; {After all, call the QuickRep preview method} GridRep.PreviewModal; {or Preview if you prefer} finally with Grid.DataSource.DataSet do begin GotoBook(BMark); FreeBook(BMark); EnableControls; end; end; end;
可以发一份给我么?或者帖出来。谢谢。
[email protected]
position , i write a component , only use it but too simpe,if you want i send you!
哪里有源码?
[email protected]
Printer.BeginDoc ;
pringer.canvas.lineto(x,y) //画线
pringet.canvas.textout(...)//打印文字
Printer.EndDoc;
end;
[email protected] qiandeng:
我也知道是这样做,但是不知道怎样去定位画线的位置x,y,表格有宽,高,怎样去很好的控制,要画行表格,要画列表格。
Creating a Quick Report layout at runtime to print DBGrid's contents First make a new form, name it as TGridReport and drop a TQuickRep on it.
Rename you QuickRep to GridRep. Then make a Preview that receives a DBGrid as parameter, just like this: procedure TGridReport.Preview(Grid: TDBGrid);
var
i, CurrentLeft, CurrentTop : integer;
BMark: TBook;
begin
GridRep.Dataset:=Grid.DataSource.DataSet; if not GridRep.Bands.HasColumnHeader then
GridRep.Bands.HasColumnHeader:=true; if not GridRep.Bands.HasDetail then
GridRep.Bands.HasDetail:=true; GridRep.Bands.ColumnHeaderBand.Height:=Abs(Grid.TitleFont.Height) + 10;
GridRep.Bands.DetailBand.Height:=Abs(Grid.Font.Height) + 10;
CurrentLeft := 12;
CurrentTop := 6; {Record where the user stopped in the DBGrid}
BMark:=Grid.DataSource.DataSet.GetBook;
{Don't let the grid flicker while the report is running}
Grid.DataSource.DataSet.DisableControls;
try
for i:=0 to Grid.FieldCount - 1 do
begin
if (CurrentLeft + Canvas.TextWidth(Grid.Columns[i].Title.Caption)) >
(GridRep.Bands.ColumnHeaderBand.Width) then
begin
CurrentLeft := 12;
CurrentTop := CurrentTop + Canvas.TextHeight('A') + 6;
GridRep.Bands.ColumnHeaderBand.Height := GridRep.Bands.ColumnHeaderBand.Height +
(Canvas.TextHeight('A') + 10);
GridRep.Bands.DetailBand.Height := GridRep.Bands.DetailBand.Height +
(Canvas.TextHeight('A') + 10);
end;
{Create Header with QRLabels}
with TQRLabel.Create(GridRep.Bands.ColumnHeaderBand) do
begin
Parent := GridRep.Bands.ColumnHeaderBand;
Color := GridRep.Bands.ColumnHeaderBand.Color;
Left := CurrentLeft;
Top := CurrentTop;
Caption:=Grid.Columns[i].Title.Caption;
end;
{Create Detail with QRDBText}
with TQRDbText.Create(GridRep.Bands.DetailBand) do
begin
Parent := GridRep.Bands.DetailBand;
Color := GridRep.Bands.DetailBand.Color;
Left := CurrentLeft;
Top := CurrentTop;
Alignment:=Grid.Columns[i].Alignment;
AutoSize:=false;
AutoStretch:=true;
Width:=Grid.Columns[i].Width;
Dataset:=GridRep.Dataset;
DataField:=Grid.Fields[i].FieldName;
CurrentLeft:=CurrentLeft + (Grid.Columns[i].Width) + 15;
end;
end; lblPage.Left := bdTitle.Width - lblPage.Width - 10;
lblDate.Left := bdTitle.Width - lblDate.Width - 10; {After all, call the QuickRep preview method}
GridRep.PreviewModal; {or Preview if you prefer} finally
with Grid.DataSource.DataSet do
begin
GotoBook(BMark);
FreeBook(BMark);
EnableControls;
end;
end;
end;
如果有打印StringGrid和DBGrid的源程序请也给我一份
[email protected] 请注明id和别名!收到后每个程序20分
谁帮忙给我也发一个
[email protected]
你给的代码自己有用过么?
我编译不通过 ,说lblpage,bdTitle 没定义。我不清楚这两个怎么定义。要加入什么单元???
谢谢。