⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordunit.pas

📁 工程预算系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
        if ntup+90>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<qflist.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;     //end while
    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 dtfltoWord(mygrid:TStringGrid);
var
  i,j:integer;
  ntopdis,nleftdis,nbottomdis,nrightdis:integer;//报表上,下,左,右边距的值
  dy:integer;                                //报表纸张的宽度和高度
  nh,nb:integer;                                   //标题离纸的高度
  ntop:integer;                                //表头离纸的高度
  nbottomtop:integer;                          //纸张表注部分所占的高度
  nhheight:integer;                           //表头边框的高度
  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赋值
  getdtfl(true);

  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:=3;  ntmppage:=0;
  while ntempcount<=dtfllist.Count do
  begin
    ntup:=ntop+nhheight;
    for i:=ntempcount to dtfllist.Count-1 do
    begin
      nmax:=1;
      for j:=1 to mygrid.ColCount-1 do
      begin
        nmin:=getlinecount(calfl(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 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:=3;

    while ntempcount<=dtfllist.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;

      bztoword1(wddoc,wdapp,mygrid);     //表注部分导到word
      bttoword4(mygrid,wddoc,wdapp);      //表头部分导到word
      ntup:=ntop+nhheight;
      for i:=ntempcount to dtfllist.Count-1 do
      begin
      //  rcj:=Tjc_rcj(dtfllist.Items[i]);
        nmax:=1;
        for j:=1 to mygrid.ColCount-1 do
        begin
          nmin:=getlinecount(calfl(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(i-2));
          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(calfl(i,mygrid,j))
          else if (i=dtfllist.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<dtfllist.Count) then
            wdapp.Selection.TypeText(calfl(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(dtfllist.Count)+'],请稍候....................';
        mainform.StatusBar1.Update;

        ntup:=ntup+nht*nmax;

        if ntup+90>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<dtfllist.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;     //end while
    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;

{万用表导到Excel}
procedure wybtoWord(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赋值
  getwyb(strselectid);



  if Trim(array_dyxx[1])='0' then
  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((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<=wyblist.Count do
    begin
      ntup:=ntop+nhheight;
      for i:=ntempcount to wyblist.Count-1 do
      begin
        nmax:=1;
        for j:=1 to mygrid.ColCount-1 do
        begin
          nmin:=getlinecount(calwyb(i,mygrid,j),mygrid.ColWidths[j]);
          if nmin>nmax then
            nmax:=nmin;
        end;
        ntup:=ntup+nht*nmax;
        if ntup+30>nbottomtop then
          break;
      end;
      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 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<=wyblist.Count do
    begin
     if oldpage<>0 then oldpage:=wdapp.Selection.Information[wdActiveEndAdjustedPageNumbe

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -