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

📄 wordunit.pas

📁 工程预算系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      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:=getstr(array_jbxx[34]);
      end;
    end;

  nunit:=wdLine;
  ncount:=getline(0);
  nindex:=0;

  wdapp.Selection.MoveDown(nunit,ncount,nindex);
  wdapp.Selection.TypeParagraph;
//  mainform.wordapp.Selection.Font.Name := '宋体';
//  mainform.wordapp.Selection.Font.Size := 9;
end;
{把表注部分导入Word}
procedure bztoword;
var
  wdAutoFit,WdTableBehavior,nindex:OleVariant;
  ncount,nrow,ncol,nunit:OleVariant;
  nitem:integer;
begin
  nitem:=1;
  mainform.wordapp.Selection.Font.Name := Trim(array_jbxx[14]);
//  mainform.wordapp.Selection.Font.Color :=;
  mainform.wordapp.Selection.Font.Size := strtoint(array_jbxx[15]);
  mainform.wordapp.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
  mainform.wordapp.Selection.TypeText(Trim(array_jbxx[12]));
  mainform.wordapp.Selection.TypeParagraph;
  mainform.wordapp.Selection.ParagraphFormat.Alignment := wdAlignParagraphJustify;
  mainform.wordapp.Selection.Font.Name := '宋体';
  mainform.wordapp.Selection.Font.Size := 9;
  if getline(0)>=1 then
  begin
    WdTableBehavior:=wdWord9TableBehavior;
    wdAutoFit:=wdAutoFitFixed;
    mainform.wordapp.Selection.Tables.Add(mainform.wordapp.Selection.Range,getline(0),3,
                              WdTableBehavior,wdAutoFit);
    with  mainform.wordapp.Selection.Tables.Item(nitem) do
    begin
      Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderRight).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderTop).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderDiagonalDown).LineStyle:=wdLineStyleNone;
      Borders.Item(wdBorderDiagonalUp).LineStyle:=wdLineStyleNone;
      Borders.Shadow := False;
      if Trim(array_jbxx[26])<>'' then
      begin
        nrow:=1;  ncol:=1;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[26]);
      end;
      if Trim(array_jbxx[27])<>'' then
      begin
        nrow:=2;  ncol:=1;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[27]);
      end;
      if Trim(array_jbxx[28])<>'' then
      begin
        nrow:=3;  ncol:=1;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[28]);
      end;
      if Trim(array_jbxx[29])<>'' then
      begin
        nrow:=1;  ncol:=2;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[29]);
      end;
      if Trim(array_jbxx[30])<>'' then
      begin
        nrow:=2;  ncol:=2;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[30]);
      end;
      if Trim(array_jbxx[31])<>'' then
      begin
        nrow:=3;  ncol:=2;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[31]);
      end;
      if Trim(array_jbxx[32])<>'' then
      begin
        nrow:=1;  ncol:=3;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[32]);
      end;
      if Trim(array_jbxx[33])<>'' then
      begin
        nrow:=2;  ncol:=3;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[33]);
      end;
      if Trim(array_jbxx[34])<>'' then
      begin
        nrow:=3;  ncol:=3;
        Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
        Cell(nrow,ncol).Range.Text:=Trim(array_jbxx[34]);
      end;
    end;
  end;
  nunit:=wdLine;
  ncount:=getline(0);
  nindex:=0;
  mainform.wordapp.Selection.MoveDown(nunit,ncount,nindex);
  mainform.wordapp.Selection.TypeParagraph;
//  mainform.wordapp.Selection.Font.Name := '宋体';
//  mainform.wordapp.Selection.Font.Size := 9;
end;
//结束表注上的定义

procedure bttoword1(mygrid:Tstringgrid;const wwddoc,wwdapp:OleVariant);
var
  i,j:integer;
  ndown:integer;
  nright:integer;
  nr,nc:integer;   //距左边
  nrowcount:integer;
  wdAutoFit,WdTableBehavior:OleVariant;
  ncount,nunit,nindex:Variant;
  ncol:integer;
  nitem,nht:integer;
  nrow:integer;
  wddoc,wdapp:OleVariant;
  rtemp:real;
  b_flag:boolean;
begin
b_flag:=False;
  wddoc:=wwddoc;
  wdapp:=wwdapp;
  nitem:=1;
  nrow:=1;
  nht:=strtoint(array_jbxx[48]);
  if Trim(array_jbxx[1])='1' then
    nc:=strtoint(array_jbxx[45])      //总列数
  else
    nc:=strtoint(array_jbxx[45])-1;

   nr:=1;

  nrowcount:=mygrid.RowCount;
  WdTableBehavior:=wdWord9TableBehavior;
  wdAutoFit:=wdAutoFitFixed;

  wddoc.Tables.Add(wdapp.Selection.Range,nr,nc,
                            WdTableBehavior,wdAutoFit);
    nrow:=1;      nindex:=1;
  for j:=1 to nc do
    wdapp.Selection.Tables.Item(nitem).Cell(nrow,j).Column.Width:=20;

  for j:=0 to mygrid.ColCount-1 do
  begin

    if Trim(array_jbxx[1])='1' then
    begin
      rtemp:=mygrid.ColWidths[j]*0.75;
      wdapp.Selection.Tables.Item(nitem).Cell(nrow,j+1).Column.Width:=20;
      wdapp.Selection.Tables.Item(nitem).Cell(nrow,j+1).Column.Width:=rtemp;
    end
    else
    begin
      if j>=1 then
        wdapp.Selection.Tables.Item(nitem).Cell(nrow,j).Column.Width:=mygrid.ColWidths[j]*0.75;

    end;
  end;
  for j:=1 to nr do
    wdapp.Selection.Tables.Item(nitem).Cell(j,ncol).Row.Height:=nht*0.75;

  nunit:=wdLine;
  ncount:=1;
  nindex:=0;

  wdapp.Selection.MoveDown(nunit,ncount,nindex);

  ncount:=strtoint(array_jbxx[44]);         //表头总行数
  wdapp.Selection.InsertRowsAbove(ncount);
  nunit:=wdLine;
  ncount:=1;
  nindex:=0;
  wdapp.Selection.MoveUp(nunit,ncount,nindex);

  if Trim(array_jbxx[1])='1' then
  begin
    if nrowcount=6 then
    begin
      nrow:=1; ncol:=1;
      wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
      wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).VerticalAlignment:=wdAlignParagraphCenter;
      wdapp.Selection.TypeText('序号');
      nunit:=wdCharacter;
      ncount:=1;
      nindex:=0;
      wdapp.Selection.MoveRight(nunit,ncount,nindex);
    end
    else if nrowcount>6 then
    begin
      nrow:=strtoint(array_jbxx[44])-1;
      nunit:=wdCharacter;
      ncount:=1;
      nindex:=1;
      wdapp.Selection.MoveRight(nunit,ncount,nindex);
      nunit:=wdLine;
      ncount:=nrow;
      nindex:=1;

      wdapp.Selection.MoveDown(nunit,ncount,nindex);

      wdapp.Selection.Cells.Merge;
      wdapp.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
      wdapp.Selection.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
      wdapp.Selection.TypeText('序'+#13+'号');
      nunit:=wdCharacter;
      ncount:=1;
      nindex:=0;
      wdapp.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
        b_flag:=True;
     //   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;
          wdapp.Selection.MoveDown(nunit,ncount,nindex);
          if nright>0 then
          begin
            nunit:=wdCharacter;
            ncount:=nright;
            nindex:=1;
            wdapp.Selection.MoveRight(nunit,ncount,nindex);
          end;
          wdapp.Selection.Cells.Merge;
          wdapp.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
          wdapp.Selection.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
          wdapp.Selection.TypeText(gettitle(mygrid.Cells[j,i]));
          nunit:=wdCharacter;
          ncount:=1;
          nindex:=0;
          if j<mygrid.ColCount-1 then
          wdapp.Selection.MoveRight(nunit,ncount,nindex);
        end
        else
        begin
          if nright>0 then
          begin
            nunit:=wdCharacter;
            ncount:=nright+1;
            nindex:=1;
            wdapp.Selection.MoveRight(nunit,ncount,nindex);
            wdapp.Selection.Cells.Merge;
          end;
          wdapp.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
        //  wdapp.Selection.Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
          wdapp.Selection.TypeText(gettitle(mygrid.Cells[j,i]));
          nunit:=wdCharacter;
          ncount:=1;
          nindex:=0;
          if j<mygrid.ColCount-1 then
            wdapp.Selection.MoveRight(nunit,ncount,nindex);
        end;
      end
      else
      begin
        if b_flag=False then
        begin
            nunit:=wdCharacter;
            ncount:=1;
            nindex:=0;
            wdapp.Selection.MoveRight(nunit,ncount,nindex);
        end;
      end;
    end;
  end;
  nrow:=strtoint(array_jbxx[44])+1;  ncol:=1;
  wdapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Select;
{  nunit:=wdLine;
  ncount:=1;
  nindex:=0;

  wdapp.Selection.MoveDown(nunit,ncount,nindex);


  nunit:=wdCharacter;
  ncount:=nc-1;
  nindex:=0;
  wdapp.Selection.MoveLeft(nunit,ncount,nindex); }
end;

{表头导到Word}
procedure bttoword(mygrid:Tstringgrid);
var
  i,j:integer;
  ndown:integer;
  nright:integer;
  nr,nc:integer;   //距左边
  nrowcount:integer;
  wdAutoFit,WdTableBehavior,nindex:OleVariant;
  ncount,nunit:OleVariant;
  nrow,ncol:integer;
  nitem,nht:integer;
begin
  nitem:=1;
  ncol:=1;
  nht:=strtoint(array_jbxx[48]);
  if Trim(array_jbxx[1])='1' then
    nc:=strtoint(array_jbxx[45])      //总列数
  else
    nc:=strtoint(array_jbxx[45])-1;
  nr:=strtoint(array_jbxx[44])+1;         //表头总行数
  nrowcount:=mygrid.RowCount;
  WdTableBehavior:=wdWord9TableBehavior;
  wdAutoFit:=wdAutoFitFixed;
  mainform.wordapp.Selection.Tables.Add(mainform.wordapp.Selection.Range,nr,nc,
                            WdTableBehavior,wdAutoFit);
    nrow:=1;
  for j:=0 to mygrid.ColCount-1 do
  begin

    if Trim(array_jbxx[1])='1' then
      mainform.wordapp.Selection.Tables.Item(mainform.wordapp.Selection.Tables.Count).Cell(nrow,j+1).Column.Width:=mygrid.ColWidths[j]*0.75

    else
    begin
      if j>=1 then
        mainform.wordapp.Selection.Tables.Item(nitem).Cell(nrow,j).Column.Width:=mygrid.ColWidths[j]*0.75;

    end;
  end;
  for j:=1 to nr do
    mainform.wordapp.Selection.Tables.Item(nitem).Cell(j,ncol).Row.Height:=nht*0.75;

  if Trim(array_jbxx[1])='1' then
  begin
    if nrowcount=6 then
    begin
      nrow:=1; ncol:=1;
      mainform.wordapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
      mainform.wordapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).VerticalAlignment:=wdAlignParagraphCenter;
      mainform.wordapp.Selection.Tables.Item(nitem).Cell(nrow,ncol).Range.Text:='序号';
      nunit:=wdCharacter;

⌨️ 快捷键说明

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