做了个模板,其中有一个大表格,占两页。我用tables(1).range.copy复制,然后要怎么paste才能让新粘贴的表格另起一页啊?现在出来的效果总是和第一个表格合并。我快被ms的range搞疯了!求高人解救!!!

解决方案 »

  1.   

    type
      TWord = class
      private
        WordApp: TWordApplication;
        procedure InsertSectionBreak;
      public
        destructor Destroy; override;
        function   Open(FileName: String): Boolean;
        procedure  CopyTable;
        procedure  PasteTable;
        procedure  SetTableText(TableNum, Row, Column: Integer; Text: String);
        procedure  InsertRows(RowCount: Integer);
        procedure  MoveEnd;
        procedure  MoveBack;
        procedure  MoveRight;
        procedure  DelRow(Row: Integer);
        procedure  Save(FileName: String);
    end;function IsExistsProcess(ProcessName: String): Boolean;implementation{ TWord }procedure TWord.CopyTable;
    begin
      WordApp.ActiveDocument.Tables.Item(1).Select;
      WordApp.Selection.Copy;
    end;procedure TWord.DelRow(Row: Integer);
    begin
      //self.WordApp.ActiveDocument.Tables.Item(TableNum).Rows.Last.Delete;
    end;destructor TWord.Destroy;
    //var
    //  Saved: OleVariant;
    begin
      //Saved:= false;
      self.WordApp.Disconnect;
      //self.WordApp.Quit(Saved);
      self.WordApp.Quit;
      self.WordApp.Free;
      inherited;
    end;procedure TWord.InsertRows(RowCount: Integer);
    var
      OleVar: OleVariant;
    begin
      OleVar:= RowCount;
      self.WordApp.Selection.InsertRows(OleVar);
      //WordDoc.Application.Selection.InsertRows(OleVar);
    end;procedure TWord.InsertSectionBreak;
    var
      SectionBreak: OleVariant;
    begin
      SectionBreak:= wdSectionBreakNextPage;
      self.WordApp.Selection.InsertBreak(SectionBreak);
      //self.WordApp.Selection.Sections.Last
      with self.WordApp.Selection.Sections.Last.Headers.Item(1).PageNumbers do
      begin
        NumberStyle:= wdPageNumberStyleArabic;
        HeadingLevelForChapter:= 0;
        IncludeChapterNumber:= false;
        ChapterPageSeparator:= wdSeparatorHyphen;
        RestartNumberingAtSection:= true;
        StartingNumber:= 1;
      end;
    end;procedure TWord.MoveBack;
    var
      ovUnit, ovCount, ovExtend: OleVariant;
    begin
      ovCount:= 1;
      ovUnit := wdCharacter;
      self.WordApp.Selection.MoveLeft(ovUnit, ovCount, ovExtend);
    end;procedure TWord.MoveEnd;
    var
      ovUnit: OleVariant;
    begin
      ovUnit:= wdStory;
      self.WordApp.Selection.EndKey(ovUnit, EmptyParam);
    end;procedure TWord.MoveRight;
    var
      ovUnit, ovCount, ovExtend: OleVariant;
    begin
      ovCount:= 1;
      ovUnit := wdCharacter;
      self.WordApp.Selection.MoveRight(ovUnit, ovCount, ovExtend);
    end;function TWord.Open(FileName: String): Boolean;
    var
      WordFileName: OleVariant;
    begin
      Result:= true;
      WordFileName:= FileName;
      try
        self.WordApp:= TWordApplication.Create(nil);
        self.WordApp.Visible := false;
        self.WordApp.Documents.Open(WordFileName, EmptyParam, EmptyParam, EmptyParam,
          EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
          EmptyParam, EmptyParam);
       except
         Result:= false;
       end;
    end;procedure TWord.PasteTable;
    begin
      InsertSectionBreak;
      self.WordApp.Selection.Paste;
    end;procedure TWord.Save(FileName: String);
    var
      WordFileName: OleVariant;
    begin
      if FileExists(FileName) then DeleteFile(FileName);
      WordFileName:= FileName;
      self.WordApp.ActiveDocument.SaveAs(WordFileName, EmptyParam, EmptyParam,
       EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
       EmptyParam, EmptyParam);
    end;procedure TWord.SetTableText(TableNum, Row, Column: Integer; Text: String);
    begin
      self.WordApp.ActiveDocument.Tables.Item(TableNum).
       Cell(Row, Column).Range.Text:= Text;
    end;
      

  2.   

    不是不可以实现,有专门控制word的教程。