有关打印 请问!·我从数据库里面筛选出了一些数据,然后我把他们显示在listview里面,然后我就想他们打印出来,用哪个qiuckrep控 件,可是具体该怎么搞我不怎么清楚,哪个高手兄弟能帮帮忙吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 const ChiefTitle:string='主标题; InferiorTitle:string='次标题';{---------------------打印函数---------------------------}function TFormOfprint.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.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 if OListView.Columns[i].width>0 then 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)+edition_print+ ' / ' + 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) +edition_print+ ' / ' + IntToStr(NumPages)); // 打印报表主要标题 Font.Size := 18; if Printer.Orientation= poPortrait then TextOut((printer.pagewidth - TextWidth(ChiefTitle)) div 2, Round(0.9 * v),ChiefTitle) else TextOut((printer.pagewidth - TextWidth(ChiefTitle)) div 2, Round(0.5 * 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 if OListView.Columns[CurCol+1].width>0 then 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; delphi TFileStream文件拆分有问题,急急! 谁能用indy9.0编写邮件特快专递程序? 高手帮忙获取网易POPO的对话内容! 求教:如果替换字符串指定位置的字符? 软件源码下载??? 把数据库中的数据转换到Excel文件中时,数据库中的身份证号在Excel文件中显示成科学计数形式,如何才能正常显示成身份证号? 如何取得系统时间 有哈尔滨的DELPHI程序员吗? 一个简单问题在线等待) help....有关于combobox的一个问题? 文件流(文件合并)问题? 关于DBGrid的疑惑
InferiorTitle:string='次标题';{---------------------打印函数---------------------------}
function TFormOfprint.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.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
if OListView.Columns[i].width>0 then
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)+edition_print+ ' / ' + 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) +edition_print+ ' / ' + IntToStr(NumPages)); // 打印报表主要标题
Font.Size := 18;
if Printer.Orientation= poPortrait then
TextOut((printer.pagewidth - TextWidth(ChiefTitle)) div 2, Round(0.9 * v),ChiefTitle)
else
TextOut((printer.pagewidth - TextWidth(ChiefTitle)) div 2, Round(0.5 * 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
if OListView.Columns[CurCol+1].width>0 then
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;