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

📄 wordunit.pas

📁 工程预算系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      ncount:=1;
      nindex:=0;
      mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
    end
    else if nrowcount>6 then
    begin
      nunit:=wdLine;
      ncount:=nr-2;
      nindex:=1;
      mainform.wordapp.Selection.MoveDown(nunit,ncount,nindex);
      mainform.wordapp.Selection.Cells.Merge;
      mainform.wordapp.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
      mainform.wordapp.Selection.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
      mainform.wordapp.Selection.TypeText('序'+#13+'号');
      nunit:=wdCharacter;
      ncount:=1;
      nindex:=0;
      mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
    end;
  end;

  for i:=5 to strtoint(array_jbxx[44])+4 do   //TStringGrid.Row
  begin
    for j:=1 to strtoint(array_jbxx[45])-1 do //TStringGrid.Col
    begin
      if Trim(mygrid.Cells[j,i])<>'' then
      begin
     //   ntop:=getheightup(mygrid.Cells[j,i]);
        ndown:=getheightdown(mygrid.Cells[j,i]);
   //     nleft:=getwidthl(mygrid.Cells[j,i]);
        nright:=getwidthr(mygrid.Cells[j,i]);
        if ndown>0 then
        begin
          nunit:=wdLine;
          ncount:=ndown;
          nindex:=1;
          mainform.wordapp.Selection.MoveDown(nunit,ncount,nindex);
          if nright>0 then
          begin
            nunit:=wdCharacter;
            ncount:=nright;
            nindex:=1;
            mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
          end;
          mainform.wordapp.Selection.Cells.Merge;
          mainform.wordapp.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
          mainform.wordapp.Selection.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
          mainform.wordapp.Selection.TypeText(gettitle(mygrid.Cells[j,i]));
          nunit:=wdCharacter;
          ncount:=1;
          nindex:=0;
          mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
        end
        else
        begin
          if nright>0 then
          begin
            nunit:=wdCharacter;
            ncount:=nright+1;
            nindex:=1;
            mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
            mainform.wordapp.Selection.Cells.Merge;
          end;
          mainform.wordapp.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
          mainform.wordapp.Selection.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
          mainform.wordapp.Selection.TypeText(gettitle(mygrid.Cells[j,i]));
          nunit:=wdCharacter;
          ncount:=1;
          nindex:=0;
          mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
        end;
      end;
    end;
  end;
  nunit:=wdLine;
  ncount:=1;
  nindex:=0;
  mainform.wordapp.Selection.MoveDown(nunit,ncount,nindex);
  nunit:=wdCharacter;
  ncount:=nc-1;
  nindex:=0;
  mainform.wordapp.Selection.MoveLeft(nunit,ncount,nindex);
  mainform.wordapp.Selection.TypeText('nnnnn');
    nunit:=wdCharacter;
  ncount:=nc;
  nindex:=0;
//  mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
end;

{把人材机导入Word 中}
procedure rcjtoword(mygrid:Tstringgrid;b_flag:boolean);
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:OleVariant;
begin
  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 b_flag then
    getrcj
  else
    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]));

  lineword;

  try
    Template := EmptyParam;
    NewTemplate := EmptyParam;
    type1 := 1;
    v1:= true;  ItemIndex :=1;
    mainform.wordapp.Documents.Add(Template,NewTemplate,type1,v1);  //.wordapp.Documents.Item(ItemIndex)
    mainform.worddoc.ConnectTo(mainform.wordapp.Documents.Item(ItemIndex));
    if Trim(array_jbxx[8])='0' then      //判断是否是纵向打印
      mainform.wordapp.Documents.Item(itemindex).PageSetup.Orientation := wdOrientLandscape;// 横向打印
//      mainform.worddoc.PageSetup.Orientation := wdOrientLandscape;// 横向打印
//    mainform.worddoc.PageSetup.TopMargin:=ntopdis;
//    mainform.worddoc.PageSetup.BottomMargin:=nbottomdis;
//    mainform.worddoc.PageSetup.LeftMargin:=nleftdis;
//    mainform.worddoc.PageSetup.RightMargin:=nrightdis;
    mainform.wordapp.Documents.Item(itemindex).PageSetup.TopMargin:=ntopdis;
    mainform.wordapp.Documents.Item(itemindex).PageSetup.BottomMargin:=nbottomdis;
    mainform.wordapp.Documents.Item(itemindex).PageSetup.LeftMargin:=nleftdis;
    mainform.wordapp.Documents.Item(itemindex).PageSetup.RightMargin:=nrightdis;
    ntempcount:=0;
    while ntempcount<=rcjlist.Count-1 do
    begin
      bztoword;     //表注部分导到word
      bttoword(mygrid);      //表头部分导到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
          mainform.wordapp.Selection.TypeText(rcj.column1);
          nunit:=wdCharacter;
          ncount:=1;
          nindex:=0;
          mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);

        end;

        for j:=1 to mygrid.ColCount-1 do
        begin
          mainform.wordapp.Selection.TypeText(calrcj(i,mygrid,j));
          nunit:=wdCharacter;
          ncount:=1;
          nindex:=0;
          mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
{      showmessage(calrcj(i,mygrid,j));
        if Trim(array_jbxx[1])='1' then
        begin
          if j=0 then
            mainform.wordapp.Selection.TypeText(rcj.column1)
          else
            mainform.wordapp.Selection.TypeText(calrcj(i,mygrid,j));
        end
        else
        begin
          if j>=1 then
          begin
            mainform.wordapp.Selection.TypeText(calrcj(i,mygrid,j));
          end; }
        end;
        ntup:=ntup+nht*nmax;

        if ntup+90>nbottomtop then
        begin

          break;
        end;
        nunit:=wdCharacter;
        ncount:=1;
        nindex:=0;
        mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
        nunit:=wdLine;
        ncount:=1;
        nindex:=0;
        mainform.wordapp.Selection.MoveDown(nunit,ncount,nindex);
        if i<rcjlist.Count-1 then
          mainform.wordapp.Selection.InsertRowsAbove(ncount);
        ntempcount:=i+2;
      end;
        nunit:=wdCharacter;
        ncount:=1;
        nindex:=0;
        mainform.wordapp.Selection.MoveRight(nunit,ncount,nindex);
        nunit:=wdLine;
        ncount:=1;
        nindex:=0;
        mainform.wordapp.Selection.MoveDown(nunit,ncount,nindex);
      mainform.wordapp.Selection.TypeParagraph;

    end;  ///while ntmepcount<=rcjlist.count-1  }

//    mainform.worddoc.Close;
//    mainform.wordapp.Quit;
  except
    screen.Cursor:=crdefault;
  end;
  screen.Cursor:=crdefault;
  mainform.statusbar1.Panels[2].Text:='导入Word成功!';
  mainform.statusbar1.Update;
  application.MessageBox('导入Word成功','温馨提示',mb_iconinformation);

{
  nhheight:=gethead(mygrid,strtoint(array_jbxx[48]));

  if Trim(array_jbxx[8])='1' then
    dy:=getpageh(0,True)
  else
    dy:=getpageh(0,False);

  ntempcount:=0;
  while ntempcount<=rcjlist.Count-1 do
  begin
    inc(npage);
    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;

      ntempcount:=i+2;
    end;

  end;
  nrow:=npage*strtoint(array_jbxx[44])+rcjlist.Count;
  if Trim(array_jbxx[1])='1' then
    ncol:=mygrid.ColCount
  else
    ncol:=mygrid.ColCount-1;
  lineword;
  try
//    Template := EmptyParam;
//    NewTemplate := EmptyParam;
//    type1 := 1;
//    v1:= true;  ItemIndex :=1;
//    mainform.wordapp.Documents.Add(Template,NewTemplate,type1,v1);
//    mainform.worddoc.ConnectTo(mainform.wordapp.Documents.Item(ItemIndex));
    if Trim(array_jbxx[8])='0' then      //判断是否是纵向打印
      mainform.worddoc.PageSetup.Orientation := wdOrientLandscape;// 横向打印
    mainform.worddoc.PageSetup.TopMargin:=ntopdis;
    mainform.worddoc.PageSetup.BottomMargin:=nbottomdis;
    mainform.worddoc.PageSetup.LeftMargin:=nleftdis;
    mainform.worddoc.PageSetup.RightMargin:=nrightdis;
    mainform.worddoc.Tables.AddOld(mainform.worddoc.Range,nrow,ncol);

    ntempcount:=0;
    while ntempcount<=rcjlist.Count-1 do
    begin
      //创建表头部分
      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
          v:=TfrMemoview.Create;
          v.SetBounds(nleftdis,ntup,mygrid.ColWidths[0],nht*nmax);
          v.FrameTyp:=15;
          v.Font.Name:='宋字';
          v.Alignment:=10;
          v.Memo.Add(rcj.column1);
 //         page.Objects.Add(v);
        end;

        for j:=1 to mygrid.ColCount-1 do
        begin
          v:=TfrMemoView.Create;
          v.SetBounds(getl(mygrid,j,nleftdis),ntup,mygrid.ColWidths[j],nht*nmax);
          v.FrameTyp:=15;
          v.Font.Name:='宋字';
          if array_jbxx[47]='1' then
          begin
            if isnumber(calrcj(i,mygrid,j))=0 then
            begin
              if getlinecount(calrcj(i,mygrid,j),mygrid.ColWidths[j])>=2 then
                v.Font.Size:=6;
            end;
          end;
          v.Alignment:=getalignment(mygrid,j);

          if (lowercase(Trim(mygrid.Cells[j,1]))='mc') then
            v.Memo.Add(calrcj(i,mygrid,j))
          else if (i=rcjlist.Count-1) and (Trim(array_jbxx[46])='1')  and (Trim(mygrid.Cells[j,4])='') then
            v.Memo.Add('')
          else if (i<rcjlist.Count) then
            v.Memo.Add(calrcj(i,mygrid,j));

         // page.Objects.Add(v);
        end;   //end for j

        ntup:=ntup+nht*nmax;
        if ntup+30>nbottomtop then
          break;

        ntempcount:=i+2;
      end;   //end for i:=ntempcount
//      createbzx(frrep,npage,ntup-30);
    end;     //end while
  except
    screen.Cursor:=crdefault;

⌨️ 快捷键说明

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