有关打印STRINGGRID方面问题,请各位高手相助.先谢过了!!! ( 积分: 100 )

  • 主题发起人 主题发起人 super-ljc
  • 开始时间 开始时间
S

super-ljc

Unregistered / Unconfirmed
GUEST, unregistred user!
经过上网查找终于找到能打印stringgrid的源码 由于我不懂打印知识 不知怎样调解为每列按实际列宽度我发现打出来宽度是平均的 那位高手给我修改一下使打出来和实际一样 ;
如第一列长为40 字符 2列是12字符 请指教 以下为源码 请一定告我是如何作的源码!
procedure printstringgrid(stringgrid: TbsSkinStringGrid;
caption: string;
rq: tdatetime);
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;
collen: array[0..6] of integer;
//我加的想改变其列宽
begin
n := 0;
collen[0]:=0;
collen[1]:=30;
collen[2]:=-20;
collen[3]:=30;
collen[4]:=-20;
collen[5]:=10;
collen[6]:=-10;
decodedate(rq, 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.begin
Doc;
CX := trunc(PointX * 1.5);
CY := PointY * 3;
widthw := (printer.PageWidth - cx) div stringgrid.ColCount;
printer.Canvas.Pen.Width := 15;
printer.Canvas.Font.Size := 20;
printer.Canvas.Font.Name := '楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3, m, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for i := 0 to stringgrid.RowCount - 2do
begin
for j := 0 to stringgrid.ColCount - 1do
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, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for w := 0 to stringgrid.ColCountdo
begin
printer.Canvas.TextOut(pointx + widthw * w, pointy + m + m + m div 3, '' + stringgrid.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) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(pointx + widthw * j, pointy + m + m + m div 3, stringgrid.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 > printer.PageHeight - 2 * cx then
begin
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.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) * (stringgrid.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) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(printer.PageWidth div 2 - cx, printer.PageHeight - cx div 4, '第 ' + inttostr(printer.PageNumber) + ' 页');
printer.EndDoc;
end;
 
经过上网查找终于找到能打印stringgrid的源码 由于我不懂打印知识 不知怎样调解为每列按实际列宽度我发现打出来宽度是平均的 那位高手给我修改一下使打出来和实际一样 ;
如第一列长为40 字符 2列是12字符 请指教 以下为源码 请一定告我是如何作的源码!
procedure printstringgrid(stringgrid: TbsSkinStringGrid;
caption: string;
rq: tdatetime);
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;
collen: array[0..6] of integer;
//我加的想改变其列宽
begin
n := 0;
collen[0]:=0;
collen[1]:=30;
collen[2]:=-20;
collen[3]:=30;
collen[4]:=-20;
collen[5]:=10;
collen[6]:=-10;
decodedate(rq, 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.begin
Doc;
CX := trunc(PointX * 1.5);
CY := PointY * 3;
widthw := (printer.PageWidth - cx) div stringgrid.ColCount;
printer.Canvas.Pen.Width := 15;
printer.Canvas.Font.Size := 20;
printer.Canvas.Font.Name := '楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3, m, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for i := 0 to stringgrid.RowCount - 2do
begin
for j := 0 to stringgrid.ColCount - 1do
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, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for w := 0 to stringgrid.ColCountdo
begin
printer.Canvas.TextOut(pointx + widthw * w, pointy + m + m + m div 3, '' + stringgrid.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) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(pointx + widthw * j, pointy + m + m + m div 3, stringgrid.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 > printer.PageHeight - 2 * cx then
begin
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.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) * (stringgrid.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) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(printer.PageWidth div 2 - cx, printer.PageHeight - cx div 4, '第 ' + inttostr(printer.PageNumber) + ' 页');
printer.EndDoc;
end;
 
曾经我也做过这样的程序,这个好象只能设置输出的起始位置,不可以设置结束位置,比如:cell1内容较多,那么在输出cell2时就会把cell1的长出部分覆盖掉.其实也不是覆盖掉,而是cell1的多出部分根本就不输出.
 
用AnyLib吧,自由界面和报表的完美解决方案!
http://www.anylib.com
 
谢谢 但我要的是这个程序其他目前不考虑!
 
没 办法我用的quickreport实现了! 用onneeddata
 
后退
顶部