打印Stringgrid的内容(转)
var
i,j,m,k,n,w,y,p:integer;
PointX,PointY,LCount,RCount,CX,CY,Widthw,Heightw:integer;
year,month,day,hour,min,sec,hsec:word;
date,time:string;
begin
n:=0;
decodedate(now,year,month,day);
decodetime(now,hour,min,sec,hsec);
date:=inttostr(year)+'年'+inttostr(month)+'月'+inttostr(day)+'日';
time:=inttostr(hour)+'时'+inttostr(min)+'分'+inttostr(sec)+'秒 ';
n:=application.MessageBox('确实要打印吗?',' 打印提示',3);
if n<>6 then exit;
PointX:=GetDeviceCaps(printer.Handle,LOGPIXELSX)div 3;
PointY:=GetDeviceCaps(printer.Handle,LOGPIXELSY)div 3;
m:=GetDeviceCaps(printer.handle,LOGPIXELSX)div 3;
n:=0;
printer.BeginDoc;
CX:=trunc(PointX*1.5);
CY:=PointY*3;
widthw:=(printer.PageWidth-cx)div stringgrid1.ColCount ;
printer.Canvas.Pen.Width:=15;
printer.Canvas.Font.Size:=20;
printer.Canvas.Font.Name:='楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3,m,'清单');
printer.Canvas.Pen.Width:=2;
printer.Canvas.Font.Size:=10;
printer.Canvas.MoveTo(pointx ,pointy+m*2);
printer.Canvas.LineTo((widthw+cx div 15)*(stringgrid1.ColCount) ,pointy+m*2);
printer.Canvas.TextOut(widthw,pointy+m+cx div 4,date);
printer.Canvas.TextOut((stringgrid1.ColCount-2)*widthw,pointy+m +cx div 4,'打印者:'+czy);
for i:=0 to stringgrid1.RowCount-2 do
begin
for j:=0 to stringgrid1.ColCount-1 do
begin
if (PointX=GetDeviceCaps(printer.Handle,LOGPIXELSX)div 3)and (PointY=GetDeviceCaps(printer.Handle,LOGPIXELSY)div 3)and(n=1) then
begin
printer.Canvas.Pen.Width:=15;
printer.Canvas.Font.Size:=20;
printer.Canvas.Font.Name:='楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3,m,'清单');
printer.Canvas.Pen.Width:=2;
printer.Canvas.Font.Size:=10;
printer.Canvas.MoveTo(pointx ,pointy+m*2);
printer.Canvas.LineTo((widthw+cx div 15)*(stringgrid1.ColCount) ,pointy+m*2);
printer.Canvas.TextOut(widthw,pointy+m+cx div 4,date);
printer.Canvas.TextOut((stringgrid1.ColCount-2)*widthw,pointy+m +cx div 4,'打印者:'+czy);
for w:=0 to stringgrid1.ColCount do
begin
printer.Canvas.TextOut(pointx+widthw*w,pointy+m+m+m div 3 ,' '+stringgrid1.Cells[w,0]);
printer.Canvas.MoveTo(pointx+widthw*w ,pointy+2*m );
printer.Canvas.LineTo(pointx+widthw*w,pointy+m*3);
end;
pointy:=pointy+m ;
printer.Canvas.MoveTo(pointx ,pointy+m*2);
printer.Canvas.LineTo((widthw+cx div 15)*(stringgrid1.ColCount),pointy+m*2);
end;
printer.Canvas.TextOut(pointx+widthw*j,pointy+m+m+m div 3 ,' '+stringgrid1.Cells[j,i]);
printer.Canvas.MoveTo(pointx+widthw*j ,pointy+2*m );
printer.Canvas.LineTo(pointx+widthw*j,pointy+m*3);
end;
printer.Canvas.MoveTo(pointx+widthw*j ,pointy+2*m );
printer.Canvas.LineTo(pointx+widthw*j,pointy+m*3);
pointy:=pointy+m ;
if pointy+m&gt;printer.PageHeight-2*cx then
begin
printer.Canvas.MoveTo(pointx ,pointy+m*2);
printer.Canvas.LineTo((widthw+cx div 15)*(stringgrid1.ColCount),pointy+m*2);
PointX:=GetDeviceCaps(printer.Handle,LOGPIXELSX)div 3;
PointY:=GetDeviceCaps(printer.Handle,LOGPIXELSY)div 3;
n:=1;
printer.Canvas.MoveTo(pointx ,pointy+m*2);
printer.Canvas.LineTo((widthw+cx div 15)*(stringgrid1.ColCount),pointy+m*2);
printer.Canvas.TextOut(printer.PageWidth div 2-cx,printer.PageHeight-cx div 4,'第 '+inttostr(printer.PageNumber )+' 页');
printer.NewPage;
end;
PointX:=GetDeviceCaps(printer.Handle,LOGPIXELSX)div 3;
printer.Canvas.MoveTo(pointx ,pointy+m*2);
printer.Canvas.LineTo((widthw+cx div 15)*(stringgrid1.ColCount),pointy+m*2);
end;
printer.Canvas.TextOut(printer.PageWidth div 2-cx,printer.PageHeight-cx div 4,'第 '+inttostr(printer.PageNumber )+' 页');
printer.EndDoc;
end;