📄 wordunit.pas
字号:
Abort;
end; }
end;
procedure rcjtoword1(mygrid:Tstringgrid;IsAllrcj:TdmAllrcj);
var
i,j:integer;
ntopdis,nleftdis,nbottomdis,nrightdis:integer;//报表上,下,左,右边距的值
dy:integer; //报表纸张的宽度和高度
nh,nb:integer; //标题离纸的高度
ntop:integer; //表头离纸的高度
nbottomtop:integer; //纸张表注部分所占的高度
nhheight:integer; //表头边框的高度
rcj:Tjc_rcj;
ntup:integer;
strselectid:string;
ntempcount:integer;
nmin,nmax:integer;
nht:integer;
Template,NewTemplate,type1,v1,ItemIndex:OleVariant;
ncount,nunit,nindex,wdapp,wddoc:OleVariant;
oldpage:OleVariant;
ntmppage:integer;
begin
oldpage:=0;
nk:=1;
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,(getactiveform as TFrm_ys).temp_grid); //给临时的grid赋值
if IsAllrcj = dmAllrcj then
getrcj
else if IsAllrcj = dmJc then
getjc(PData2((getactiveform as Tfrm_ys).tv_js.Selected.Data)^.bh);
if Trim(array_jbxx[8])='1' then
dy:=getpageh(0,True)
else
dy:=getpageh(0,False);
nht:=strtoint(array_jbxx[48]);
nleftdis:=strtoint(array_jbxx[4])*3;
ntopdis:=strtoint(array_jbxx[5])*3;
nrightdis:=strtoint(array_jbxx[6])*3;
nbottomdis:=strtoint(array_jbxx[7])*3;
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; //作为换页的依据;
nhheight:=gethead(mygrid,strtoint(array_jbxx[48]));
ntempcount:=0; ntmppage:=0;
while ntempcount<=rcjlist.Count do
begin
ntup:=ntop+nhheight;
for i:=ntempcount to rcjlist.Count-1 do
begin
nmax:=1;
for j:=1 to mygrid.ColCount-1 do
begin
nmin:=getlinecount(calrcj(i,mygrid,j),mygrid.ColWidths[j]);
if nmin>nmax then
nmax:=nmin;
end;
ntup:=ntup+nht*nmax;
if ntup+30>nbottomtop then
break;
end;
ntempcount:=i+1;
inc(ntmppage);
end;
npagecount:=ntmppage;
lineword1;
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;
ntempcount:=0; npagetmp:=0;
while ntempcount<=rcjlist.Count do
begin
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 rcjlist.Count-1 do
begin
rcj:=Tjc_rcj(rcjlist.Items[i]);
nmax:=1;
for j:=1 to mygrid.ColCount-1 do
begin
nmin:=getlinecount(calrcj(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 (lowercase(Trim(mygrid.Cells[j,1]))='mc') then
wdapp.Selection.TypeText(calrcj(i,mygrid,j))
else if (i=rcjlist.Count-1) and (Trim(array_jbxx[46])='1') and (Trim(mygrid.Cells[j,4])='') then
wdapp.Selection.TypeText('')
else if (i<rcjlist.Count) then
wdapp.Selection.TypeText(calrcj(i,mygrid,j));
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
ntup:=ntup+nht*nmax;
if ntup+110>nbottomtop then
begin
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<rcjlist.Count-1 then
wdapp.Selection.InsertRowsAbove(ncount);
end;
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; ///while ntmepcount<=rcjlist.count-1 }
wddoc.saveas(word_path);
wddoc.Close;
wdapp.Quit;
except
screen.Cursor:=crdefault;
wddoc.saveas(word_path);
wddoc.Close;
wdapp.Quit;
end;
screen.Cursor:=crdefault;
mainform.statusbar1.Panels[2].Text:='导入Word成功!';
mainform.statusbar1.Update;
application.MessageBox('导入Word成功','温馨提示',mb_iconinformation);
end;
{取费表导到Word}
procedure qftoWord(mygrid:TStringGrid);
var
i,j:integer;
ntopdis,nleftdis,nbottomdis,nrightdis:integer;//报表上,下,左,右边距的值
dy:integer; //报表纸张的宽度和高度
nh,nb:integer; //标题离纸的高度
ntop:integer; //表头离纸的高度
nbottomtop:integer; //纸张表注部分所占的高度
nhheight:integer; //表头边框的高度
rcj:Tjc_rcj;
ntup:integer;
strselectid:string;
ntempcount:integer;
nmin,nmax:integer;
nht:integer;
Template,NewTemplate,type1,v1,ItemIndex:OleVariant;
ncount,nunit,nindex,wdapp,wddoc:OleVariant;
oldpage:OleVariant;
ntmppage:integer;
begin
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,(getactiveform as TFrm_ys).temp_grid); //给临时的grid赋值
getqf(pdata2((getactiveform as TFrm_ys).tv_js.Selected.Data)^.bh);
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((getactiveform as TFrm_ys).temp_grid,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; //作为换页的依据;
ntempcount:=0; ntmppage:=0;
while ntempcount<=qflist.Count do
begin
ntup:=ntop+nhheight;
for i:=ntempcount to qflist.Count-1 do
begin
nmax:=1;
for j:=1 to mygrid.ColCount-1 do
begin
nmin:=getlinecount(calqf(i,mygrid,j),mygrid.ColWidths[j]);
if nmin>nmax then
nmax:=nmin;
end;
ntup:=ntup+nht*nmax;
if ntup+30>nbottomtop then
break;
end; //end for i:=ntempcount
ntempcount:=i+1;
inc(ntmppage);
end; //end while
npagecount:=ntmppage;
lineword1;
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;
ntempcount:=0; npagetmp:=0;
while ntempcount<=qflist.Count do
begin
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 qflist.Count-1 do
begin
rcj:=Tjc_rcj(qflist.Items[i]);
nmax:=1;
for j:=1 to mygrid.ColCount-1 do
begin
nmin:=getlinecount(calqf(i,mygrid,j),mygrid.ColWidths[j]);
if nmin>nmax then
nmax:=nmin;
end;
if Trim(array_jbxx[1])='1' then
begin
wdapp.Selection.TypeText(inttostr(rcj.flag));
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
for j:=1 to mygrid.ColCount-1 do
begin
if (lowercase(Trim((getactiveform as TFrm_ys).temp_grid.Cells[j,1]))='mc') then
wdapp.Selection.TypeText(calqf(i,mygrid,j))
else if (i=qflist.Count-1) and (Trim(array_jbxx[46])='1') and (Trim((getactiveform as TFrm_ys).temp_grid.Cells[j,4])='') then
wdapp.Selection.TypeText('')
else if (i<qflist.Count) then
wdapp.Selection.TypeText(calqf(i,mygrid,j));
nunit:=wdCharacter;
ncount:=1;
nindex:=0;
wdapp.Selection.MoveRight(nunit,ncount,nindex);
end;
mainform.statusbar1.Panels[2].Text:='正在检查数据并导入到Excel['+inttostr(i+1)+'/'+inttostr(qflist.Count)+'],请稍候....................';
mainform.StatusBar1.Update;
ntup:=ntup+nht*nmax;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -