我现在想用C#去控制word,包括对控制word的环境支持(是.net本身集成,还是有第三方插件),写入并保存为word格式,
对文本框,表格,图表对象的插入控制。
现在特别急需这方面的东东,
但苦于对这方面的知识又了解甚少,
还请各位大侠们多多帮助,提供些对操作word的源码、例子或书籍。
小弟感激不尽!
在此先谢过了!!!
对文本框,表格,图表对象的插入控制。
现在特别急需这方面的东东,
但苦于对这方面的知识又了解甚少,
还请各位大侠们多多帮助,提供些对操作word的源码、例子或书籍。
小弟感激不尽!
在此先谢过了!!!
Word.ApplicationClass WordApp = new Word.ApplicationClass(); // give any file name of your choice.
object fileName = "D:\\aa.doc";
object readOnly = false;
object isVisible = false; // the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;
WordApp.Visible = false;
// Make word visible, so you can see what's happening
//WordApp.Visible = true;
// Open the document that was chosen by the dialog
Word.Document aDoc = WordApp.Documents.Open(ref fileName,
ref missing, ref readOnly, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages;
int num = aDoc.ComputeStatistics(stat, ref missing);
System.Console.WriteLine("The number of pages in doc is {0}",
num); foreach (Word.Range r in aDoc.Words)
{
Debug.WriteLine("value:" + r.Text); } System.Console.ReadLine();
object o = false;
aDoc.Close(ref o, ref missing, ref missing);
WordApp.Quit(ref o, ref missing, ref missing);
http://www.cnblogs.com/zc22/archive/2006/11/22/569089.html
public void test()
{
WordDocuments doc = new WordDocuments();
doc.CreateDocumentWithTemplate(@"E:\temp\ReportAppendixTemplate.doc");
doc.AppendText("附件二、明细表");
doc.AppendTable(5, 5);
doc.Visible = true;
doc.SaveAsDocument(@"e:\test\test.doc");
}
编程靠google,很多东西搜索都是可以搜索的到的。自己需要理解一下代码。