📄 qd_worde.pas
字号:
wdapp.Selection.TypeText(calgclqd(i,mygrid,j));
end; //end else
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end; //end for j:=1 to mygrid.colcount
//创建本页合计
if array_jbxx[46]='1' then //总的合计前面加上小计
begin
if i+1=gcqdlist.Count-1 then
begin
if array_dyxx[1]='1' then
begin
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
nunit:=wdLine;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
wdapp.Selection.InsertRowsAbove(ncount);
b_frist:=True;
ntup:=ntup+nht*nmax;
nmax:=1;
if Trim(array_jbxx[1])='1' then
begin
wdapp.Selection.TypeText('');
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
for ncol:=1 to mygrid.ColCount-1 do
begin
if (lowercase(Trim(mygrid.Cells[ncol,1]))='mc') then
wdapp.Selection.TypeText('本页小计')
else if Trim(mygrid.Cells[ncol,4])='' then
wdapp.Selection.TypeText('')
else if i<gcqdlist.Count then
wdapp.Selection.TypeText(Trim(floattostr(array_hj[ncol])));
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
end; // end array_dyxx[1] 如果是本页小计
end; //end if i+1 qcqdlist.count-1
end; //end if array_jbxx[46]='1' then
ntup:=ntup+nht*nmax;
if ntup+50>nbottomtop then
begin
b_break:=True;
break;
end;
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
nunit:=wdLine;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
if i<gcqdlist.Count-1 then
wdapp.Selection.InsertRowsAbove(ncount);
end; //end for i:=ntmepcount
if b_frist=False then
begin
if array_dyxx[1]='1' then
begin
if b_break then
begin
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
nunit:=wdLine;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
end;
wdapp.Selection.InsertRowsAbove(ncount);
if Trim(array_jbxx[1])='1' then
begin
wdapp.Selection.TypeText('');
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
for ncol:=1 to mygrid.ColCount-1 do
begin
if (lowercase(Trim(mygrid.Cells[ncol,1]))='mc') then
wdapp.Selection.TypeText('本页小计')
else if Trim(mygrid.Cells[ncol,4])='' then
wdapp.Selection.TypeText('')
else if i<gcqdlist.Count then
wdapp.Selection.TypeText(Trim(floattostr(array_hj[ncol])));
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end; //end for
end; // end; if array_dyxx[1]
end; // end ifif b_frist=False then
ntempcount:=i+1;
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
nunit:=wdLine;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
wdapp.Selection.TypeParagraph;
bzxtoword(wddoc,wdapp,mygrid);
end; //end while
wddoc.saveas(word_path);
wddoc.Close;
wdapp.Quit;
except
screen.Cursor:=crdefault;
wddoc.saveas(word_path);
wddoc.Close;
wdapp.Quit;
end; //end try
screen.Cursor:=crdefault;
mainform.statusbar1.Panels[2].Text:='导入Word成功!';
mainform.statusbar1.Update;
application.MessageBox('导入Word成功','温馨提示',mb_iconinformation);
end;
end;
{创建分部分项工程量清单综合单价计算表} {分页来处理}
procedure gcqdjsbtoword(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;
ntmpxm:integer;
strxh:string; //清单的序号
nxhtop,nxhheight:integer; //序号的高度和宽度
nrowcount:integer;
ntmpcol:integer;
Template,NewTemplate,type1,v1,ItemIndex:OleVariant;
ncount,nunit,nindex,numrow,wdapp,wddoc:OleVariant;
oldpage:OleVariant;
nitem:integer;
ntmppage:integer;
begin
npage:=0;
oldpage:=0;
nitem:=1;
getzhdjqdlist((getactiveform as Tfrm_ys).StringGrid1); //取得清单数据
nrowcount:=strtoint(array_jbxx[44])+1; //用于创建本页的清单 的编号
ntmpcol:=1; //用于选定第一个空格
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+65+nh; //表头开始离纸的高度
nbottomtop:=dy-nbottomdis-nb; //作为换页的依据;
ntempcount:=0;
ntmppage:=0;
while ntempcount<=gcqdlist.Count-1 do
begin
ntup:=ntop+nhheight;
for i:=ntempcount to gcqdlist.Count-1 do
begin
rcj:=Tjc_rcj(gcqdlist.Items[i]);
if rcj.flag=0 then
begin
if i>0 then
break;
end
else
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;
ntup:=ntup+nht*nmax;
if ntup+50>nbottomtop then
break;
end; //end else
end;
ntempcount:=i+2;
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;
nmax:=1;
b_frist:=False;
ntempcount:=0;
setqdjsblist(0); strxh:=Tjc_rcj(gcqdlist.Items[0]).column1;
npagetmp:=0;
while ntempcount<=gcqdlist.Count-1 do
begin
b_break:=False;
nxhheight:=0;
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;
qdbztoword(wddoc,wdapp); //表注部分导到word {这里必须要重写}
bttoword4(mygrid,wddoc,wdapp); //表头部分导到word
ntup:=ntop+nhheight;
for i:=ntempcount to gcqdlist.Count-1 do
begin
rcj:=Tjc_rcj(gcqdlist.Items[i]);
if rcj.flag=0 then
begin
if i>0 then
begin
if Trim(array_jbxx[1])='1' then
begin
wdapp.Selection.Tables.Item(nitem).Cell(nrowcount,ntmpcol).Select;
if nxhheight>=1 then
begin
if nxhheight=1 then
wdapp.Selection.TypeText(strxh)
else if nxhheight>1 then
begin
nunit:=wdLine;
ncount:=nxhheight-2;
nindex:=1;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
wdapp.Selection.Cells.Merge;
wdapp.Selection.TypeText(strxh);
end;
end;
if i<gcqdlist.Count then
begin
nunit:=wdLine;
ncount:=2;
nindex:=0;
wdapp.Selection.MoveDown(nunit,ncount,nindex);
wdapp.Selection.Rows.Delete;
end;
setqdjsblist(i);
strxh:=Tjc_rcj(gcqdlist.Items[i]).column1;
ntempcount:=i+1;
break;
end; //end 序号
end; // end if i>0 then
end // end if rcj.flag=0 then
else
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;
nxhheight:=nxhheight+1;
wdapp.Selection.TypeText('');
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
for j:=1 to mygrid.ColCount-1 do
begin
if rcj.flag=4 then
wdapp.Selection.TypeText(calgclqd(i,mygrid,j))
else if rcj.flag=5 then
begin
if (lowercase(Trim(mygrid.Cells[j,1]))='mc') then
wdapp.Selection.TypeText(calgclqd(i,mygrid,j))
else if Trim(mygrid.Cells[j,4])='' then
wdapp.Selection.TypeText('')
else if i<gcqdlist.Count then
wdapp.Selection.TypeText(calgclqd(i,mygrid,j));
end;
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end; //end for j:=1
end; //end else
ntup:=ntup+nht*nmax;
if ntup+50>nbottomtop then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -