📄 qd_worde.pas
字号:
unit qd_worde;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, ImgList, StdCtrls, Buttons, ComCtrls, dbctrls, menus,Variants,
Math,ComObj,Gauges,grids,DBGrids,pubunit,Contnrs,printers, FR_Class,DBGridEh,
Word2000,Office2000,Excel2000,hu_pub,pub_rep;
{计算表表注部分导到Word文档中}
procedure qdbztoword(wddoc,wdapp:OleVariant);
{把分部分项工程量清单,措施项目导到Word文档中}
procedure gcqdtoword(mygrid:TStringGrid); //报表导到Word
{创建分部分项工程量清单综合单价计算表} {分页来处理}
procedure gcqdjsbtoword(mygrid:TStringGrid); //报表导到Word
{把其他项目工程量清单报表导到Word文档中}
procedure qtxmqdtoword(mygrid:TStringGrid); //报表导到Word
{把零星工作项目工作表报表导到Word文档中}
procedure lxxmtoword(mygrid:TStringGrid); //报表导到Word
{把人才机综合报表导到Word文档中}
procedure rcjzhtoword(mygrid:TStringGrid;IsAllrcj:TdmAllrcj); //报表导到Word
{把分部分项工程量清单,措施项目导到Excel}
procedure gcqdtoexcel(mygrid:TStringGrid); //报表导到Excel
{把分部分项工程量清单综合单价计算表导到Excel中} {分页来处理}
procedure gcqdjsbtoexcel(mygrid:TStringGrid); //报表导到Excel
{把其他项目工程量清单报表导到Excel}
procedure qtxmqdtoexcel(mygrid:TStringGrid); //报表导到Excel
{把零星工作项目工作表报表导到excel 中}
procedure lxxmtoexcel(mygrid:TStringGrid); //报表导到Excel
{取得报表的表头标题列的名称}
function gettitleexcel(str:string):string;
{在一个字符串中用|替代回车键}
function replacehomeexcel(str:string):string;
{把表头信息导到Excel}
procedure qdbttoExcel(mygrid:TStringGrid;nr:integer);
{对表注上的信息进行编辑}
procedure qdExportbzstoExcel(mygrid:TStringGrid;nr:integer);
{把人才机综合报表导到excel}
procedure rcjzhtoexcel(mygrid:TStringGrid;IsAllrcj:TdmAllrcj); //报表导到Excel
{把清单万用表表格导到Word}
procedure qdwybtoword(mygrid:TStringGrid); //报表导到Excel
{把清单万用表表格导到Excel}
procedure qdwybtoexcel(mygrid:TStringGrid); //报表导到Excel
{创建自由表}
procedure qdfmtoword;
{把取费汇总报表导到excel}
procedure qfhztoexcel(mygrid:TStringGrid); //报表导到Excel
{把取费汇总报表导到Word文档中}
procedure qdqftoword(mygrid:TStringGrid); //报表导到Word
implementation
uses ys,qd_rep,wordunit,main,Excelunit;
{计算表表注部分导到Word文档中}
procedure qdbztoword(wddoc,wdapp:OleVariant);
var
wdAutoFit,WdTableBehavior,nindex:OleVariant;
ncount,nrow,ncol,nunit:OleVariant;
nitem:integer;
ntemp,nw,i:integer;
nwidth:integer;
nc:integer;
begin
ntemp:=0;
for i:=0 to (getactiveform as Tfrm_ys).temp_grid.ColCount-1 do
ntemp:=ntemp+(getactiveform as Tfrm_ys).temp_grid.ColWidths[i];
if Trim(array_jbxx[1])='1' then //表头框架的宽度
nw:=ntemp
else
nw:=ntemp-(getactiveform as Tfrm_ys).temp_grid.ColWidths[0];
nwidth:=round(nw/3);
nitem:=1;
wdapp.Selection.Font.Name := Trim(array_jbxx[14]);
// mainform.wordapp.Selection.Font.Color :=;
wdapp.Selection.Font.Size := strtoint(array_jbxx[15]);
wdapp.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
wdapp.Selection.TypeText(Trim(array_jbxx[12]));
wdapp.Selection.TypeParagraph;
wdapp.Selection.ParagraphFormat.Alignment := wdAlignParagraphJustify;
wdapp.Selection.Font.Name := '宋体';
wdapp.Selection.Font.Size := 9;
if getline(0)>=1 then
begin
WdTableBehavior:=wdWord9TableBehavior;
wdAutoFit:=wdAutoFitFixed;
wddoc.Tables.Add(wdapp.Selection.Range,getline(0),3,WdTableBehavior,wdAutoFit);
for nc:=1 to 3 do
mainform.wordapp.Selection.Tables.Item(nitem).Columns.Item(nc).Width:=nwidth*0.75;
// with wdapp.Selection.Tables.Item(nitem) do
// begin
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderRight).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderTop).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderDiagonalDown).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Item(wdBorderDiagonalUp).LineStyle:=wdLineStyleNone;
wdapp.Selection.Tables.Item(nitem).Borders.Shadow := False;
if Trim(array_jbxx[26])<>'' then
begin
nrow:=1; ncol:=1;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[26]);
end;
if Trim(array_jbxx[27])<>'' then
begin
nrow:=2; ncol:=1;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[27]);
end;
if Trim(array_jbxx[28])<>'' then
begin
nrow:=3; ncol:=1;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[28]);
end;
if Trim(array_jbxx[29])<>'' then
begin
nrow:=1; ncol:=2;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[29]);
end;
if Trim(array_jbxx[30])<>'' then
begin
nrow:=2; ncol:=2;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[30]);
end;
if Trim(array_jbxx[31])<>'' then
begin
nrow:=3; ncol:=2;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[31]);
end;
if Trim(array_jbxx[32])<>'' then
begin
nrow:=1; ncol:=3;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[32]);
end;
if Trim(array_jbxx[33])<>'' then
begin
nrow:=2; ncol:=3;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[33]);
end;
if Trim(array_jbxx[34])<>'' then
begin
nrow:=3; ncol:=3;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:=getqdstr(array_jbxx[34]);
end;
end;
nunit:=wdLine;
ncount:=getline(0);
nindex:=0;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
wdapp.Selection.TypeParagraph;
end;
{把分部分项工程量清单,措施项目导到Word文档中}
procedure gcqdtoword(mygrid:TStringGrid);
var
i,j,k:integer;
ntopdis,nleftdis,nbottomdis,nrightdis:integer;//报表上,下,左,右边距的值
dy:integer; //报表纸张的宽度和高度
nh,nb:integer; //标题离纸的高度
ntop:integer; //表头离纸的高度
nbottomtop:integer; //纸张表注部分所占的高度
nhheight:integer; //表头边框的高度
rcj:Tjc_rcj;
ntup:integer;
strselectid:string;
npage:integer;
ntempcount:integer;
nmin,nmax:integer;
nht:integer;
ncol:integer; //用于本页小计用
b_frist,b_break:boolean;
Template,NewTemplate,type1,v1,ItemIndex:OleVariant;
ncount,nunit,nindex,numrow,wdapp,wddoc:OleVariant;
oldpage:OleVariant;
ntmppage:integer;
begin
npage:=0;
oldpage:=0;
if (getactiveform as Tfrm_ys).TV_js.Selected<>nil then
strselectid:=PData2((getactiveform as Tfrm_ys).TV_js.Selected.Data)^.ID
else
abort;
getxx(strselectid); //取得报表基本信息
setxx(strselectid,mygrid); //给临时的grid赋值
case rep_type of
11: getqd_xmlist((getactiveform as Tfrm_ys).StringGrid1); //清单编辑
12: getqd_xmlist((getactiveform as Tfrm_ys).StringGrid1); //措施项目
end;
if array_dyxx[17]='1' then
begin
gcqdjsbtoword(mygrid);
end
else
begin
nht:=strtoint(array_jbxx[48]);
ntopdis:=strtoint(array_jbxx[5])*3;
nbottomdis:=strtoint(array_jbxx[7])*3;
nleftdis:=strtoint(array_jbxx[4])*3;
nrightdis:=strtoint(array_jbxx[6])*3;
nhheight:=gethead(mygrid,strtoint(array_jbxx[48]));
if Trim(array_jbxx[8])='1' then
dy:=getpageh(0,True)
else
dy:=getpageh(0,False);
nh:=getup(array_jbxx[26],array_jbxx[27],array_jbxx[28],array_jbxx[29],array_jbxx[30],array_jbxx[31],array_jbxx[32],array_jbxx[33],array_jbxx[34]);
nb:=getup(array_jbxx[35],array_jbxx[38],array_jbxx[41],array_jbxx[36],array_jbxx[39],array_jbxx[42],array_jbxx[37],array_jbxx[40],array_jbxx[43]);
ntop:=ntopdis+60+nh; //表头开始离纸的高度
nbottomtop:=dy-nbottomdis-nb; //作为换页的依据;
ntmppage:=0; ntempcount:=0;
while ntempcount<=gcqdlist.Count do
begin
ntup:=ntop+nhheight;
for i:=ntempcount to gcqdlist.Count-1 do
begin
nmax:=1;
for j:=1 to mygrid.ColCount-1 do
begin
nmin:=getlinecount(calgclqd(i,mygrid,j),mygrid.ColWidths[j]);
if nmin>nmax then
nmax:=nmin;
end;
if array_jbxx[46]='1' then
begin
if i+1=gcqdlist.Count-1 then //创建本页小计 因为记录不够,那就在合计前
begin
if array_dyxx[1]='1' then
begin
ntup:=ntup+nht*nmax;
nmax:=1;
end;
end;
end;
ntup:=ntup+nht*nmax;
if ntup+50>nbottomtop then
break;
end;
ntempcount:=i+1;
inc(ntmppage);
end;
npagecount:=ntmppage;
lineword1; //连接Word 文档
try
wdapp:=CreateOleObject('Word.Application');
except
application.MessageBox(pchar('与Word应用程序连接失败!请确定是否已经装有Word,或者Word应用程序已被破坏!'+#13#10
+'如有必要,请联络程序设计人员!'),'温馨提示',mb_iconexclamation);
screen.Cursor:=crdefault;
Abort;
end;
wdapp.Visible:=True;
try
Template := EmptyParam;
NewTemplate := EmptyParam;
type1 := 1;
v1:= true; ItemIndex :=1;
wddoc:=wdapp.Documents.Add(Template,NewTemplate,type1,v1); //.wordapp.Documents.Item(ItemIndex)
if Trim(array_jbxx[8])='0' then //判断是否是纵向打印
wdapp.Documents.Item(itemindex).PageSetup.Orientation := wdOrientLandscape;// 横向打印
if (ntopdis-65)<0 then
wdapp.Documents.Item(itemindex).PageSetup.TopMargin:=5
else
wdapp.Documents.Item(itemindex).PageSetup.TopMargin:=ntopdis-65;
if (nbottomdis-65)<0 then
wdapp.Documents.Item(itemindex).PageSetup.BottomMargin:=5
else
wdapp.Documents.Item(itemindex).PageSetup.BottomMargin:=nbottomdis-65;
wdapp.Documents.Item(itemindex).PageSetup.LeftMargin:=nleftdis;
wdapp.Documents.Item(itemindex).PageSetup.RightMargin:=nrightdis;
if wdapp.ActiveWindow.View.SplitSpecial= wdPaneNone then
wdapp.ActiveWindow.ActivePane.View.Type:=wdPrintView
else
wdapp.ActiveWindow.View.Type:=wdPrintView;
b_frist:=False;
ntempcount:=0; npagetmp:=0;
while ntempcount<=gcqdlist.Count do
begin
b_break:=False;
if oldpage<>0 then
oldpage:=wdapp.Selection.Information[wdActiveEndAdjustedPageNumber];
while wdapp.Selection.Information[wdActiveEndAdjustedPageNumber]<>oldpage+1 do
wdapp.Selection.TypeParagraph;
oldpage:=1;
npagetmp:=npagetmp+1;
bztoword1(wddoc,wdapp,mygrid); //表注部分导到word
bttoword4(mygrid,wddoc,wdapp); //表头部分导到word
ntup:=ntop+nhheight;
for i:=ntempcount to gcqdlist.Count-1 do
begin
rcj:=Tjc_rcj(gcqdlist.Items[i]);
nmax:=1;
for j:=1 to mygrid.ColCount-1 do
begin
nmin:=getlinecount(calgclqd(i,mygrid,j),mygrid.ColWidths[j]);
if nmin>nmax then
nmax:=nmin;
end;
if Trim(array_jbxx[1])='1' then // 这里是创建序号
begin
wdapp.Selection.TypeText(rcj.column1);
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
for j:=1 to mygrid.ColCount-1 do
begin
if isnumber(calgclqd(i,mygrid,j))=0 then
array_hj[j]:=array_hj[j]+strtofloat(calgclqd(i,mygrid,j)); // 计算本页小计
if rcj.flag=1 then
begin
if lowercase(Trim(mygrid.Cells[j,1]))='mc' then
wdapp.Selection.TypeText(calgclqd(i,mygrid,j))
else
wdapp.Selection.TypeText('');
end
else if (rcj.flag=0) or (rcj.flag=4) then
wdapp.Selection.TypeText(calgclqd(i,mygrid,j))
else if (rcj.flag=2) or (rcj.flag=3) or (rcj.flag=5) then
begin
if (lowercase(Trim(mygrid.Cells[j,1]))='mc') then
wdapp.Selection.TypeText(calgclqd(i,mygrid,j))
else if (Trim(array_jbxx[46])='1') and (Trim(mygrid.Cells[j,4])='') then
wdapp.Selection.TypeText('')
else if i<gcqdlist.Count then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -