Delphi与Word(一) 合并Word 表格中单元格
2004-09-08 16:14
375 查看
//合并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 := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := 'd:/test.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.Close;
WordDoc.Disconnect;
WordDoc.Destroy;
WordDoc := nil;
end;
if Assigned(WordApp) then // ===== 关闭Word =====
begin
WordApp.Quit;
WordApp.Disconnect;
WordApp.Destroy;
WordApp := nil;
end;
end;
end;
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 := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := 'd:/test.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.Close;
WordDoc.Disconnect;
WordDoc.Destroy;
WordDoc := nil;
end;
if Assigned(WordApp) then // ===== 关闭Word =====
begin
WordApp.Quit;
WordApp.Disconnect;
WordApp.Destroy;
WordApp := nil;
end;
end;
end;
相关文章推荐
- 用Delphi合并Word表格中单元格
- Delphi与Word(一)合并Word 表格中单元格
- Word C# 报异常 无法访问此集合中的单独的行,因为表格有纵向合并的单元格
- C# 操作在Word表格中插入新行(表格含合并行)
- Delphi向word文档中输出表格及图形
- delphi操作word基类,插入表格,分页符,日期,页码,替换,图片
- Delphi 操作word 表格
- Delphi与Word(二) 取得Word 表格中的数据
- word两个不同表格合并,防止自动调整
- delphi操作word基类,插入表格,分页符,日期,页码,替换,图片
- Delphi读取不Word中不规则表格数据并转换成标准表格
- Word C# 报异常 无法访问此集合中的单独的行,因为表格有纵向合并的单元格
- 轻松玩转word表格拆分与合并
- 【一步一步学习VBA】WORD 创建表格并合并表格
- 用DELPHI怎样生成WORD表格文档
- 轻松玩转word表格拆分与合并
- poi 导出word,导出表格(复杂表格合并行列)解决方法
- VB.net中合并word中的表格
- word中插入图片,图表,字符替换,表格填写,合并
- Delphi与Word(二)取得Word 表格中的数据