读书人

WORD编程如何能

发布时间: 2013-03-01 18:33:02 作者: rapoo

WORD编程怎么能啊
我现在有个现成的word文档,文档中有个表格,想往文档中表格里面添加数据。
网上查了下都说需要用VB来写,C#不能吗?
[解决办法]
c#可以的
c#操作word表格
[解决办法]
导入你的word模版文件


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);


向word的table插入数据

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 start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);

参考这篇文章http://hi.baidu.com/xuejianxiyang/item/72ee680cf1852ec12f4c6be3

读书人网 >C#

热点推荐