前提:
导入COM库:Microsoft word 11.0 Object Library.
引用里面就增加了:
创建新Word
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);
打开文档:
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;
object fileName = @"E:\XXXCCX\Test.doc";
oDoc = oWord.Documents.Add(ref fileName, 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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0d64405f076852a727853140f1b5ed12.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);
.表插入行
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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d8cb661a69c8a44b0477812de3b6a686.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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c3aa6c8060bdc76355141314b44b853f.gif)
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
.单元格合并
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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/47f82711beca49891e96369e762abe8d.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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9815d673fa03891fc23847dd400bcaa5.gif)
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c8e425dc1d07418a6cf15ef22a692ce7.gif)
Word.Cell cell = newTable.Cell(1, 1);
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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e4739a87443e4ea059b0b175dfafc373.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);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c4a0430bd1748603bd857217725d89e8.gif)
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/2cdd5c4e4e268c22aa8cd966e6165a4c.gif)
Word.Cell cell = newTable.Cell(1, 1);
cell.Merge(newTable.Cell(1, 2));
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/232f99fa251d5b5e86aee1709883c68a.gif)
object Rownum = 2;
object Columnnum = 2;
cell.Split(ref Rownum, ref Columnnum);
通过段落控制插入
导入COM库:Microsoft word 11.0 Object Library.
引用里面就增加了:
创建新Word
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e2d49d4baa19ebb04c7422acd2ba2a56.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9afbe06ddc72ab3861b906c01cb2dd9a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d6cbbdcd45f85d1a4c90efdebd1fbe95.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c86ffe538130dbd5b49dc679cd5edabd.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/226092b9d08b1f3765d093174c7589fc.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d8d4ab9175293c855c8376fe2773f751.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/47a36a1eab506cb251e10c75f13e2ca5.gif)
打开文档:
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/b7ece32cd5afb6eb161972000dc627f4.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9e933eedefd9c6d8756ede9658f96399.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/7e36b1793fe4c01c689ff662cb842a79.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/27c8b89a09d0e8aa7d9e2f52f3459c72.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0cd52b16c406c7014e453dd1a9b9e5da.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/2ae27e1903ff9810ddb783b928371959.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/926ac2536f3f30743711a292bc7cb706.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/aa2d6b2e275e9b700d97eed71a5fbe23.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/5c3eaa77728a6194f03ba32182840119.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e02cec9416fd56ff27e154a272718dee.gif)
导入模板
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9401230ebdfe48a1285e78cd2c28472f.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/2454f802e4c405e051366d3e1fd46769.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/731ea128fe591bd2a698df9b2380c80e.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/1e70956dcc42204a393ebe6a65b9d430.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/fe49be12cc6d950f04272c2a78c047e3.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/b973a39742d9b5f79f40f004c061d9ff.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/18b245d749223988cced2cc88df4cf2d.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/551734f7c6aa94ba7f76e31a6e0236ea.gif)
.添加新表
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9b19cb7057b8f53e54ec9bd06de3d471.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d3d164bb72a164bc1fae0b84bbfcd024.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/462a4f03c28eaa93ea42d22b752b85f5.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e26c819611bd945ac0c178d47a82d152.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/4cf0b6fd11ea4243a366724a2bbd345d.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/02a25018588fb593d753d78482bc40b2.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/a46f4340f002945351e374e7dbe96b00.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0d64405f076852a727853140f1b5ed12.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/f3420b34ce7fece94b1885836111cc3e.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e76066a3e9712bf16e34d390d7b7e335.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c6da85705a4fae123c7fdd84adcdf678.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/1e20b12f6ec7e000754af9b8cb4eb9d2.gif)
.表插入行
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d3b2e08725e8d85628de089c69c798cd.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d73e7b21d83f6dfe08ca24105e195841.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/7dd9a040db77532dd423249f1547d7cf.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/ac74b5daeeb56540955bd41fb19749a8.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/3c64e7f7830ed11bae15729db5eb2cc7.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/a31adc278c0c4c6b6d9d3c293665e0a1.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c8bf69d8d835e1b2d2e804594a566389.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d8cb661a69c8a44b0477812de3b6a686.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0b54a3e1b4457ff6741d48c92de5ca69.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/afb540c1d272216473ac1caa14239394.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/eeb79dcf03b1c01c9f73193d66f6b78c.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/4f768676ae6506d07fe49ddbccba9391.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c3aa6c8060bdc76355141314b44b853f.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/94a2cb9a5af771d841ed9b1eb43b75f3.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/3f2ac716547d664d82dea86927b09628.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/8b78d7bd0917d3be2c82e522896ce824.gif)
.单元格合并
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/fcab5477e2210f9914d9bd3eeaab89da.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c8d15c1aa7cf3276ec09783aeba7adcc.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c70b0a6db67ce1d034c1a3b974b7a436.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/8c77d091a56c65a87dbe42b58a49d43a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/10948c357c89a20d2ca671e1290129ab.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/18e698ed263276ad17d4c2a7ad2fd084.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d0bec5be603c763d590a0e769941fd0f.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/47f82711beca49891e96369e762abe8d.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/d60dea63ad6d9072effb8474a4614170.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/943f6fdf1fcb23616c762bebf5aec6cc.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/eb27dcea01d5d6b1dbcc78e6b7cbc82d.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/6c2a1a8676ff0192e52fb46609aae18d.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9815d673fa03891fc23847dd400bcaa5.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/212e717f54ec0773ac0753dcd621b161.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/fd3080ff0b6d30bd0bc516e9067cea07.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9ca847ce316748f2d34289d844f74faa.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c8e425dc1d07418a6cf15ef22a692ce7.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/78cab3a5430e2fc436ad4f07899efd9a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/ee951da901795b014136d293c495dd99.gif)
.单元格分离
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/03248b451ae70f2046951a97bc095805.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/ffa62cdca55a57b4b7921c4a894e99c7.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/a452246feac526ca951f93ef775cf604.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/05ef0ed7b04cfdc52956b522aef3f00f.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/261aa48408a37da5934925d69d7ac25c.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/1c00c5a148feb4aad5d3e66ad87d9540.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/dea4f2a90458fc98c31b8781e5cc9c52.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e4739a87443e4ea059b0b175dfafc373.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/630f0b7e9b66cea8ca50a12ff6ff863e.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/a35d87ef86009fd2c11985cf7f3a2f77.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/59978fe246301a8c79f00d60799b0031.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9810d330f2d8fb2ae7bf9bfb5f6fee0e.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c4a0430bd1748603bd857217725d89e8.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0f3282ccb829a315268b9d1e8601464a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/28c434f263584cae644f24b0a41a139a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/20c4e759a74352df67f0bc14e6f6242e.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/2cdd5c4e4e268c22aa8cd966e6165a4c.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0415c7b2cfcee850dba2022ce31c6429.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/66bf00b7943aa69efdab5298ee2673ba.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/232f99fa251d5b5e86aee1709883c68a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/ae3aebc5bea94fd268708cfd38f56d4a.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/780949fcd755d30ee4e9e2f0516eecab.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/23c1d5da69bce963fa8e5aae51ae04a0.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e4c8dde9b91e47deeba6113867deb4aa.gif)
通过段落控制插入
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/7450f976dcc899ecb5fe1171dc7b180f.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/30c38f59caf8021e300941c85862afe9.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/b1af9d3831aaaac18a7b0b0c6dfe36a2.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/8db0617915322ec6ac5738a59af71fc7.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/39853ea6f9d382a285aa6c39765bbaa8.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/8e8fda377218ea1d2a78e84e02e68287.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/3b4733b17acf67c50c7f61337b867540.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/077678bc6cfa9a2da8c2d27c6658fec6.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/e94a7c9af4336fa82785b12edfc7ea57.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/6c1ccb2fdc5593134566e9d29e886c45.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/3dc4547003886082a51c677997a37491.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/5a95ba1867877e6a6b45ad4b5bd2f740.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/0e2b1b04b790582bf88bbf3871d63609.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/9c396d1c3f582dc7867b12341356c620.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/8f934dc25caf821246505e0cc395a5f4.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/be53f32d79d2a0b98c40ea8d6a3e98ee.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/24854dbbc451b6cd5fd4256a40a81758.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/c8407706c8e7d1d5afce1790ab41f519.gif)
![[转]C#操作Word完全功略](https://i-blog.csdnimg.cn/blog_migrate/aed9d0948e6a0bfea89da6c242812490.gif)