求关于打印DBGrid和StringGrid数据的源码?谢谢

blackfiles 2001-08-17 03:52:54
要求以表格形式打印出来,有表格线。
Printer.BeginDoc ;
//How To Do
Printer.EndDoc;
...全文
231 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
flysky 2001-08-22
  • 打赏
  • 举报
回复
lblpage ,bdtitl是什么东东??????
zh430 2001-08-22
  • 打赏
  • 举报
回复
把你的E_mail留下,我把整个窗体发给你
blackfiles 2001-08-22
  • 打赏
  • 举报
回复
To zh430(伊一逸)
你给的代码自己有用过么?
我编译不通过 ,说lblpage,bdTitle 没定义。我不清楚这两个怎么定义。要加入什么单元???
谢谢。
zhbvictor 2001-08-20
  • 打赏
  • 举报
回复
gz
zh430 2001-08-20
  • 打赏
  • 举报
回复
上边的代码十分好用,只要按照上E文所述建一个打印预览窗体,然后在要打印dbgrid的窗体上调用这一过程就好了,记得dbgrid要做参数啊
logapi 2001-08-20
  • 打赏
  • 举报
回复
我也在找这个
谁帮忙给我也发一个
mfgme@21cn.com
路人丁 2001-08-20
  • 打赏
  • 举报
回复
很关注!
如果有打印StringGrid和DBGrid的源程序请也给我一份
dingzhenhhy@263.net 请注明id和别名!收到后每个程序20分
zh430 2001-08-20
  • 打赏
  • 举报
回复
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: TBookmark;
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.GetBookmark;
{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
GotoBookmark(BMark);
FreeBookmark(BMark);
EnableControls;
end;
end;
end;
blackfiles 2001-08-20
  • 打赏
  • 举报
回复
To TFPE:
blackfiles@163.net

To qiandeng:
我也知道是这样做,但是不知道怎样去定位画线的位置x,y,表格有宽,高,怎样去很好的控制,要画行表格,要画列表格。
torble 2001-08-18
  • 打赏
  • 举报
回复
呵呵~
blackfiles 2001-08-18
  • 打赏
  • 举报
回复
To chinanet:
哪里有源码?
chinanet 2001-08-18
  • 打赏
  • 举报
回复
输出到excel二次处理,csdn有原码
cslegend 2001-08-18
  • 打赏
  • 举报
回复
我也要
Cslegend@etang.com
qiandeng 2001-08-18
  • 打赏
  • 举报
回复
beign
Printer.BeginDoc ;
pringer.canvas.lineto(x,y) //画线
pringet.canvas.textout(...)//打印文字
Printer.EndDoc;
end;
DD88 2001-08-18
  • 打赏
  • 举报
回复
我页想要 : wudi0731@163.net
qq_13439718 2001-08-18
  • 打赏
  • 举报
回复
vba excel输出
lwk_hlj 2001-08-18
  • 打赏
  • 举报
回复
我也想要啊,
kevinhlj@yahoo.com
TFPE 2001-08-18
  • 打赏
  • 举报
回复
i can't find you email address !?
TFPE 2001-08-18
  • 打赏
  • 举报
回复
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!
blackfiles 2001-08-17
  • 打赏
  • 举报
回复
gz
加载更多回复(3)

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧