最近要做word的相關操作,因為要使用word2007的公式,一種是使用word自帶的Omaths,另一種是open xml sdk.所以有了這一篇文章的出現。這里查閱了相關資料和open xml sdk自帶的幫助文檔?
open xml sdk使用相關的博客: http://blog.csdn.net/songpengpeng20100202/article/category/947920
http://www.cnblogs.com/xuanhun/tag/openxml/
http://blog.csdn.net/istarsoft/article/details/5700874
http://blog.csdn.net/tx_officedev/article/category/934720
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://blog.csdn.net/april_zheng/article/details/6972222
open xml sdk下載地址: http://www.microsoft.com/en-us/download/details.aspx?id=5124
Open xml sdk目前的版本是2.0,在這個版本里的還有Open XML SDK 2.0 Productivity Tool。這個工具的主要目的是對Word、PowerPoint或者Excel文檔進行反向工程。接著,它會生成可以重新創建這個文檔的C#代碼。這個工具還能用來驗證文檔。
首先安裝好open xml sdk,然后先建工程,在工程中引用DocumentFormat.dll,在DocumentFormat.dll可能依賴于Windowsbase.dll里面的System.Io.Packaging.所以這里將Windowsbase.dll也加入引用。
接下來就是開始生成word。

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using DocumentFormat.OpenXml.Packaging; 6 using DocumentFormat.OpenXml; 7 using DocumentFormat.OpenXml.Wordprocessing; 8 using System.Xml; 9 using System.IO; 10 11 namespace CreateWordUsingOpenXml 12 { 13 class Program 14 { 15 static void Main( string [] args) 16 { 17 string filePath = " D:\\124.docx " ; 18 // Create a new Wordprocessing document 19 WordprocessingDocument wordDoc = WordprocessingDocument.Create(filePath,WordprocessingDocumentType.Document); 20 21 // add the MainDocument part in the new WordProcessing document 22 MainDocumentPart mainDocPart=wordDoc.AddNewPart<MainDocumentPart>( " application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml " , " rId1 " ); 23 mainDocPart.Document = new Document(); 24 25 wordDoc.Close(); 26 27 28 } 29 } 30 }
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
