Procedure GetWordCellStr;
var
WordApp: TWordApplication;
WordDoc: TWordDocument;
DocInx,FileName,CfCversions,IsReadOnly,AddToRctFiles,PswDocument,
PswTemplate,Revert,WPswDocument,WPswTemplate,FormatWord: OleVariant;
i,iRow,iCol: Integer;
myCell: Cell;
myRow: Row;
begin
Memo.Lines.Clear ;
// ===== 创建对象 =====
if not Assigned(WordApp) then
begin
WordApp:= TWordApplication.Create(nil);
WordApp.Visible := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
FileName := ′d:\test.doc′;
IsReadOnly:=true;
CfCversions := EmptyParam;
AddToRctFiles:= EmptyParam;
PswDocument:= EmptyParam;
PswTemplate:= EmptyParam;
Revert:= EmptyParam;
WPswDocument:= EmptyParam;
WPswTemplate:= EmptyParam;
FormatWord:= EmptyParam;
// ===== 打开文件 =====
WordApp.Documents.open(FileName,CfCversions,IsReadOnly,AddToRctFiles,
PswDocument,PswTemplate,Revert,WPswDocument,WPswTemplate,FormatWord);
// ===== 关联文件 =====
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;
end;
end;
//方法(2)==> 不规则表:只有横向合并时
For i := 1 To WordDoc.Tables.Count do &n