解决方案 »
- 请教高手,
- 急!!异构数据库数据的批量导入导出
- insert 后报错
- 关于获取服务器时间的问题,分不够再加。
- 有谁看过李维的《INSIDE VCL》,进来交流一下!
- 使用idTCpServer和IdTCPClient,当一个客户端连上来时,怎样知道它的ip地址?
- 急用:如何限制Edit中只能输入汉字?
- 求救啊!!!关于打开dataset的问题。——好急呵!!!!!!!!!
- 谁有类似QQ那样的抽屉控件?100分换
- 被“美丽心灵”唤醒的数学天才(转载)
- 请问如果查找成功怎么代码写入数据表aa呀,并且怎么样写代码把表字段显示在界面上,谢谢了
- 满分:求INDY中的 TidTcp 控件对文件传输的操作。
InferiorTitle:string='小标题;function TMainForm.PrintListview(OListView: TListView):boolean;
//-----------------------------------------------------
var
pWidth, pHeight, i: Integer;
v, h: Real;
CurItem,iColumnCount: Integer;
aCols: array of Integer;
iTotColsWidth, iInnerWidth, TopMarg, LinesOnPage, CurLine, TekstHeight, CurCol: Integer;
CurRect: TRect;
CurStr: string;
CurLeft, NumPages, TmpPos: Integer;
begin
result:=false;
if PrintDialog1.Execute then
begin
iColumnCount:= oListview.Columns.Count;
SetLength(aCols,oListview.Columns.Count+ 1);
Printer.Title := '打印报表-我是我'; //提交给打印机的名称
Printer.Copies := 1;
Printer.Orientation := poPortrait; //报表是垂直显示的
Printer.BeginDoc;
pHeight := Printer.PageHeight; //当前打印页的高度
pWidth := Printer.PageWidth; //当前打印页的宽度
v := (pHeight + (2 * GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY))) / (29.7 * 0.95);
//0.95 用来给不同机器打印机做调整因素
h := (pWidth + (2 * GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX))) / 21;
// 计算总的宽度
iTotColsWidth := 0;
for i := 0 to iColumnCount - 1 do
iTotColsWidth := iTotColsWidth + oListView.Columns[i].Width;
//计算间距
aCols[0] := Round(1.5 * h); //left margin
aCols[iColumnCount + 0] := pWidth - Round(1.5 * h); //rigth margin
iInnerWidth := aCols[iColumnCount + 0] - aCols[0]; // space between margins
//计算每行开始
for i := 0 to iColumnCount - 1 do
aCols[i + 1] := aCols[i] + Round(oListView.Columns[i].Width / iTotColsWidth * iInnerWidth);
TopMarg := Round(2.5 * v);
with Printer.Canvas do
begin
Font.Size := 10;
Font.Style := [];
Font.Name := 'Times New Roman';
Font.Color := RGB(0, 0, 0);
TekstHeight := Printer.Canvas.TextHeight('dummy');
LinesOnPage := Round((PHeight - (5 * v)) / TekstHeight);
NumPages := 1;
// 得到所有的打印机列表
while (NumPages * LinesOnPage) < oListView.Items.Count do
inc(NumPages);
// 开始打印
CurLine := 0;
for CurItem := 0 to oListView.Items.Count - 1 do
begin
if (CurLine > LinesOnPage) or (CurLine = 0) then
begin
if (CurLine > LinesOnPage) then Printer.NewPage;
CurLine := 1;
if Printer.PageNumber = NumPages then
begin
MoveTo(aCols[1], topMarg);
for i := 1 to iColumnCount - 1 do
begin
LineTo(aCols[i], TopMarg + (TekstHeight * (oListView.Items.Count - CurItem + 2)));
MoveTo(aCols[i + 1], topMarg);
end;
end
else
begin
//在数据中移动垂直线 <显示分割线>
for i := 1 to iColumnCount - 1 do
begin
MoveTo(aCols[i], topMarg);
LineTo(aCols[i], TopMarg + (TekstHeight * (LinesOnPage + 1)));
end;
end; Font.Style := [fsBold];
// 打印listview的columns项目
for i := 0 to iColumnCount - 1 do
begin
TextRect(Rect(aCols[i] + Round(0.1 * h), TopMarg - Round(0.1 * v), aCols[i + 1] - Round(0.1 * h)
, TopMarg + TekstHeight - Round(0.1 * v)), ((aCols[i + 1] - aCols[i]) div 2) +
aCols[i] - (TextWidth(oListview.Columns.Items[i].Caption) div 2),
TopMarg - Round(0.1 * v), oListview.Columns.Items[i].Caption);
end; // 在column headers之下拖动水平线
MoveTo(aCols[0] - Round(0.1 * h), TopMarg + TekstHeight - Round(0.05 * v));
LineTo(aCols[iColumnCount] + Round(0.1 * h), TopMarg + TekstHeight - Round(0.05 * v)); //打印日期和页码
Font.Size := 8;
Font.Style := [];
TmpPos := (TextWidth('日期: ' + DateToStr(Date) + ' 页码: ' +
IntToStr(Printer.PageNumber) + ' / ' + IntToStr(NumPages))) div 2; TmpPos := PWidth - Round(1.5 * h) - (TmpPos * 2); Font.Size := 8;
Font.Style := [];
TextOut(TmpPos,printer.PageHeight-Round(0.5 * v), '日期: ' + DateToStr(Date) +
' 页码: ' + IntToStr(Printer.PageNumber) + ' / ' + IntToStr(NumPages)); // 打印报表主要标题
Font.Size := 18;
TextOut((printer.pagewidth - TextWidth(ChiefTitle)) div 2, Round(0.9 * v),ChiefTitle);
// 打印报表次要标题
Font.Size := 14;
TextOut((printer.pagewidth - TextWidth(InferiorTitle)) div 2, Round(1.6 * v),InferiorTitle);
Font.Size := 10;
Font.Style := [];
end; CurRect.Top := TopMarg + (CurLine * TekstHeight);
CurRect.Bottom := TopMarg + ((CurLine + 1) * TekstHeight); // 打印listview的内容
for CurCol := -1 to iColumnCount - 2 do
begin
CurRect.Left := aCols[CurCol + 1] + Round(0.1 * h);
CurRect.Right := aCols[CurCol + 2] - Round(0.1 * h);
try
if CurCol = -1 then
CurStr := oListView.Items[CurItem].Caption
else
CurStr := oListView.Items[CurItem].SubItems[CurCol];
except
CurStr := '';
end;
CurLeft := CurRect.Left; // 排的左边
//把数据写到TextRect
TextRect(CurRect, CurLeft, CurRect.Top, CurStr); end;
Inc(CurLine);
end;
end;
Printer.EndDoc;
result:=true;
end;end;