用Delphi合并Word表格中单元格

更新时间:2023-05-16 21:11:36 阅读: 评论:0

 Delphi合并Word表格中单元格
] //合并Word 表格中单元格
procedure mergeWordCell;
var WordApp: TWordApplication;
    WordDoc: TWordDocument;眼霜的使用方法
    DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
    PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
    i,iRow,iCol:integer;
    myCell:Cell;
    myRow:Row;
begin
  memo1.Lines.Clear ;

    // ===== 创建对象 =====
    if not Assigned(WordApp) then                         
    begin
      WordApp:= TWordApplication.Create(nil);
      WordApp.Visible := fal;
    end;
    if not Assigned(WordDoc) then
      WordDoc:= TWordDocument.Create(nil);
  try
tremme    DocInx:=1;
    oFileName := 'd: est.doc';
    oReadOnly:=true;
    CfCversions := EmptyParam;
    AddToRctFiles:= EmptyParam;
    PswDocument:= EmptyParam;
    PswTemplate:= EmptyParam;
    oRevert:= EmptyParam;
英语签名
    WPswDocument:= EmptyParam;
    WPswTemplate:= EmptyParam;
    oFormat:= EmptyParam;     
    // ===== 打开文件 =====                         
    WordApp.Documents.open(oFileName,CfCversions,oReadOnly,AddToRctFiles,
       PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
    // ===== 关联文件 =====
    WordDoc.ConnectTo(WordApp.Documents.Item(DocInx)); 


    //合并第一、二列
        iStart:=WordDoc.Tables.Item(i).Cell(1,1).Range.Start;
        myCol:= WordDoc.Tables.Item(i).Columns.Item(2);
        iEnd:=myCol.Cells.Item(myCol.Cells.Count).Range.End_;
        myRange:=WordDoc.Range;
        myRange.Start:=iStart;
        myRange.End_ :=iEnd;
        myRange.Cells.Merge;

  finally
    if Assigned(WordDoc) then     // ===== 关闭文件 =====
    begin
      WordDoc.Clo;
      WordDoc.Disconnect;
      WordDoc.Destroy;
      WordDoc := nil;
    end;
    if Assigned(WordApp) then      // ===== 关闭Word =====
    begin
      WordApp.Quit;
英语大师      WordApp.Disconnect;
      WordApp.Destroy;
      WordApp := nil;
    end;
pirates  end;
end;
取得Word 表格中的数据
//取得Word 表格中的数据
procedure getWordCellStr;
var WordApp: TWordApplication;
    WordDoc: TWordDocument;
    DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
    PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
    i,iRow,iCol:integer;
    myCell:Cell;
    myRow:Row;
begin
  memo1.Lines.Clear ;

    // ===== 创建对象 =====
    if not Assigned(WordApp) then                         
    begin
      WordApp:= TWordApplication.Create(nil);
      WordApp.Visible := fal;
    end;
    if not Assigned(WordDoc) then
      WordDoc:= TWordDocument.Create(nil);
  try
    DocInx:=1;
    oFileName := 'd: est.doc';
    oReadOnly:=true;
    CfCversions := EmptyParam;
    AddToRctFiles:= EmptyParam;
    PswDocument:= EmptyParam;
    PswTemplate:= EmptyParam;
杨百翰大学    oRevert:= EmptyParam;
    WPswDocument:= EmptyParam;
    WPswTemplate:= EmptyParam;
    oFormat:= EmptyParam;     
    // ===== 打开文件 =====                         
    WordApp.Documents.open(oFileName,CfCversions,oReadOnly,AddToRctFiles,
       PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
    // ===== 关联文件 =====
    WordDoc.ConnectTo(WordApp.Documents.Item(DocInx)); 


    //方法(1)==> 规则表
    For i := 1 To WordDoc.Tables.Count do      //  i 希望英语单词个表
    begin                                      // iRow 
      For iRow := 1 To WordDoc.Tables.Item(i).Rows.Count do     
      begin                                            // iCol
        For icol := 1 To WordDoc.Tables.Item(i).Columns.Count do
        begin
          myCell:=WordDoc.Tables.Item(i).Cell(iRow,icol);
          memo1.Lines.add(myCell.Range.Text);
        end;
founders      end;
    end;
   
    //方法(2)==> 不规则表:只有横向合并时
    For i := 1 To WordDoc.Tables.Count do              // i 个表
    begin
      For iRow := 1 To WordDoc.Tables.Item(i).Rows.Count do
      begin
        myRow:=WordDoc.Tables.Item(i).Rows.Item(iRow);// iRow 
        For icol := 1 To myRow.Cells.Count do         // iCol
        begin
          myCell:= myRow.Cells.Item(iCol) ;
          memo1.Lines.add(myCell.Range.Text);
        end;
      end;
    end;

    //方法(3)==> 不规则:横向、纵向合并时; 任何表格
    For i := 1 To WordDoc.Tables.Count do            // i 个表
    begin                                            // j Cell 
        for j := 1 To WordDoc.Tables.Item(i).Range.Cells.Count do
        begin
brittle          myCell := WordDoc.Tables.Item(i).Range.Cells.Item(j);
          memo1.Lines.add(myCell.Range.Text);
        end;
    end;

  finally
    if Assigned(WordDoc) then              // ===== 关闭文件 =====
    begin
      WordDoc.Clo;
      WordDoc.Disconnect;
      WordDoc.Destroy;
      WordDoc := nil;
    end;
    if Assigned(WordApp) then              // ===== 关闭Word =====
    begin
      WordApp.Quit;
      WordApp.Disconnect;
      WordApp.Destroy;
      WordApp := nil;
    end;
aaa培训  end;
end;

本文发布于:2023-05-16 21:11:36,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/658851.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:文件   横向   合并   眼霜   表格   英语单词   方法
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图