如何打印表格中的内容(100分)

  • 主题发起人 主题发起人 jzg2002
  • 开始时间 开始时间
J

jzg2002

Unregistered / Unconfirmed
GUEST, unregistred user!
我要用针式打印机打印表格中的内容
例如:表格中有姓名,我只把名字打印出来就行了。而姓名在表格上有了,就不需要打印了。
我首先要在窗体上把这个表格画出来,然后再打印表格中需要填写的内容。
我不清楚该用什么控件画表格和如何打印
请帮助
 
用quickreport控件,Delphi自带的 (D7就没有quickreport了,自带Rave控件),你只要看一下quickreport的DEMO,这个问题,你很容易就能解决的,
 

看下DEMO就可以解决了
 
quickreport就可以搞定了。
 
FastReport也可以。
 
我的打印全用EHLIB实现,它可以直接打印DBGRID和套打,下面是我套下的实现,希望对你有帮助:
function TFormFsBkd.PrintOut(VPrinter: TVirtualPrinter): Boolean;
var
SysManager: TIniFile;
PageWidth,PageHeight,Orientation:Integer;
NoTop,NoLeft,RQToP,RQLeft,BKBMTop,BKBMLeft:Integer;
BKDWQCTop,BKDWQCLeft,BKDWYHZHTop,BKDWYHZHLeft,BKDWKHYHTop,BKDWKHYHLeft:Integer;
SKDWQCTop,SKDWQCLeft,SKDWYHZHTop,SKDWYHZHLeft,SKDWKHYHTop,SKDWKHYHLeft:Integer;
DXJETop,DXJELeft,XXJETop,XXJELeft:Integer;
YTTop,YTLeft,ZCXMTop,ZCXMLeft:Integer;
DWMMTop,DWMCLeft:integer;
DWMCString:string;
pointx,pointy:Real;//每毫米多少点
PrintRq:string;
begin


SysManager :=TIniFile.Create(ExtractFilePath(Application.ExeName)+'SysManager.InI');
PageWidth:=SysManager.ReadInteger('FsBkd', 'PageWidth', 0);
PageHeight:=SysManager.ReadInteger('FsBkd', 'PageHeight',0);
Orientation:=SysManager.ReadInteger('FsBkd', 'Orientation',0);
PrintSetup(VPrinter,PageWidth,PageHeight,Orientation);
//获取打印机信息通常分辨率是指一英寸的点数,1英寸=2.54厘米
//取得每一英寸的点数,分x与y
if VPrinter.Printers.Count > 0 then
begin
pointx := GetDeviceCaps(VPrinter.Handle, LOGPIXELSX);
pointy := GetDeviceCaps(VPrinter.Handle, LOGPIXELSY);
end else
begin
pointx:= DefaultPrinterPixelsPerInchX;
pointy := DefaultPrinterPixelsPerInchY;
end;

//计算每毫米多少点
pointx := pointx / 25.4;
pointy := pointy / 25.4;
DWMMTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'DWMMTop', 0));
DWMCLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'DWMCLeft',0));
DWMCString:=SysManager.ReadString('FsBkd', 'DWMCString','');
NoTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'NoTop', 0));
NoLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'NoLeft',0));
RQTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'RQToP',0));
RQLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'RQLeft',0));
BKBMTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'BKBMTop',0));
BKBMLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'BKBMLeft',0));
BKDWQCTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', ' BKDWQCTop',0));
BKDWQCLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'BKDWQCLeft',0));
BKDWYHZHTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'BKDWYHZHTop',0));
BKDWYHZHLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'BKDWYHZHLeft',0));
BKDWKHYHTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'BKDWKHYHTop',0));
BKDWKHYHLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'BKDWKHYHLeft',0));
SKDWQCTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', ' SKDWQCTop',0));
SKDWQCLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'SKDWQCLeft',0));
SKDWYHZHTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'SKDWYHZHTop',0));
SKDWYHZHLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'SKDWYHZHLeft',0));
SKDWKHYHTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'SKDWKHYHTop',0));
SKDWKHYHLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'SKDWKHYHLeft',0));
DXJETop:=trunc(pointx*SysManager.ReadInteger('FsBkd', ' DXJETop',0));
DXJELeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'DXJELeft',0));
XXJETop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'XXJETop',0));
XXJELeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'XXJELeft',0));
YTTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'YTTop',0));
YTLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'YTLeft',0));
ZCXMTop:=trunc(pointx*SysManager.ReadInteger('FsBkd', 'ZCXMTop',0));
ZCXMLeft:=trunc(pointy*SysManager.ReadInteger('FsBkd', 'ZCXMLeft',0));

SysManager.Free;
//VPrinter.NewPage;
VPrinter.begin
Doc;
VPrinter.Canvas.Font.Name := '宋体';
VPrinter.Canvas.Font.Size := 11;
VPrinter.Canvas.TextOut(DWMCLeft,DWMMTop,Trim(DWMCString));
VPrinter.Canvas.TextOut(NoLeft,NoTop,Trim(EditLine_DJH.Edit1.Text));
PrintRq:=LeftStr(Trim(EditLine_RQ.EditDate.Text),4)+'年'+copy(Trim(EditLine_RQ.EditDate.Text),6,2)+'月'+RightStr(Trim(EditLine_RQ.EditDate.Text),2)+'日';
VPrinter.Canvas.TextOut(RQLeft,RQTop,Trim(PrintRq));
//VPrinter.Canvas.TextOut(BKBMLeft,BKBMTop,Trim(EditLine_BM.Text));
VPrinter.Canvas.TextOut(BKDWQCLeft,BKDWQCTop,Trim(EditLine_QC.Text));
VPrinter.Canvas.TextOut(BKDWYHZHLeft,BKDWYHZHTop,Trim(EditLine_YHZH.Edit1.Text));
VPrinter.Canvas.TextOut(BKDWKHYHLeft,BKDWKHYHTop,Trim(EditLine_KHYH.Edit1.Text));
VPrinter.Canvas.TextOut(SKDWQCLeft,SKDWQCTop,Trim(EditLine_SKQC.Text));
VPrinter.Canvas.TextOut(SKDWYHZHLeft,SKDWYHZHTop,Trim(EditLine_SKYHZH.Edit1.Text));
VPrinter.Canvas.TextOut(SKDWKHYHLeft,SKDWKHYHTop,Trim(EditLine_SKKHYH.Edit1.Text));
VPrinter.Canvas.TextOut(DXJELeft,DXJETop,Trim(EditLine_DXJE.Edit1.Text));
VPrinter.Canvas.TextOut(XXJELeft,XXJETop,Trim(EditLine_XXJE.Text));
VPrinter.Canvas.TextOut(YTLeft,YTTop,Trim(EditLine_YT.Text));
VPrinter.Canvas.TextOut(ZCXMLeft,ZCXMTop,Trim(EditLine_ZCXM.Text));
Application.ProcessMessages;
if VPrinter.Aborted then
Exit;
VPrinter.EndDoc;
//VPrinter.NewPage;
end;
 
不好意思,太长没做修改(直接复制的)
 
谢谢帮助
 
后退
顶部