用Delphi合并Word表格中单元格
2009-11-26 15:09
453 查看
用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 := false;
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));
//合并第一、二列
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;
//合并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: 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.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(一)合并Word 表格中单元格
- Word C# 报异常 无法访问此集合中的单独的行,因为表格有纵向合并的单元格
- Word C# 报异常 无法访问此集合中的单独的行,因为表格有纵向合并的单元格
- Word C# 报异常 无法访问此集合中的单独的行,因为表格有纵向合并的单元格
- Delphi与Word(一) 合并Word 表格中单元格
- Javascript合并表格中具有相同内容的单元格
- JS前端动态添加表格--包括合并指定单元格
- 用jQuery合并表格中相同文本的相邻单元格
- 使用VSTO读取WORD表格中的单元格内容的问题
- Delphi与Word(二) 取得Word 表格中的数据
- 基于jQuery的合并表格中相同文本的相邻单元格的代码
- DevExpress.XtraReports.UI.XtraTable表格如何合并单元格
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- C# 操作在Word表格中插入新行(表格含合并行)
- 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- 轻松玩转word表格拆分与合并
- 用DELPHI怎样生成WORD表格文档
- jquery合并表格中相同文本的相邻单元格
- 基于jQuery的合并表格中相同文本的相邻单元格的代码
- 一个JAVASCRIPT实用函数,完成合并表格中列中具有相同内容的列单元格的功能