导入COM库:Microsoft word 12.0 Object Library.
引用里面就增加了:
原http://support.microsoft.com/kb/316384/zh-cn#top
创建新Word
打开文档:
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord =new Word.Application();
oWord.Visible =true;
object fileName = @"E:\CCCXCXX\TestDoc.doc";
oDoc = oWord.Documents.Open(ref fileName,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);
导入模板
.添加新表
.表插入行
.单元格合并
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord =new Word.Application();
oWord.Visible =true;
oDoc = oWord.Documents.Add(ref oMissing,ref oMissing,
ref oMissing,ref oMissing);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start,ref end);
oDoc.Tables.Add(tableLocation, 3, 4,ref oMissing,
ref oMissing);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
newTable.Rows.Add(
ref beforeRow);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
Word.Cell cell = newTable.Cell(1, 1);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
cell.Merge(newTable.Cell(1, 2));
.单元格分离
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord =new Word.Application();
oWord.Visible =true;
oDoc = oWord.Documents.Add(ref oMissing,ref oMissing,
ref oMissing,ref oMissing);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start,ref end);
oDoc.Tables.Add(tableLocation, 3, 4,ref oMissing,
ref oMissing);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
newTable.Rows.Add(
ref beforeRow);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
Word.Cell cell = newTable.Cell(1, 1);
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
cell.Merge(newTable.Cell(1, 2));
object Rownum = 2;
object Columnnum = 2;
![](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
cell.Split(
ref Rownum,
ref Columnnum);
通过段落控制插入