我讀過一些提到填充單詞文檔的帖子,但我需要使用C#填充Word文檔(Office 2007)。例如,我想要一個帶有標籤[NAME]的單詞文檔,在C#中使用該標籤來放置我的值,並在ASP.NET MVC3控制器中執行所有操作。任何想法?在ASP.NET MVC3中使用C#填充單詞模板
2
A
回答
3
您可以使用Microsoft提供的OpenXML SDK來操作Word文檔。這裏有一個nice article(它實際上是一系列3篇文章中的第三篇),並附有一些例子。
0
你可以這樣做: - 介紹「榮譽徽章」到Word文檔模板 - 工作在您的Word模板 的副本 - 修改紋章從C#代碼值和保存或打印文件。
要當心用正確釋放你的話的過程,如果你把你的應用程序:)從問題中提取
0
OP的解決方案的幾個文件:
的解決方案,我發現是這樣的:
static void Main(string[] args) { Console.WriteLine("Starting up Word template updater ..."); //get path to template and instance output string docTemplatePath = @"C:\Users\user\Desktop\Doc Offices XML\earth.docx"; string docOutputPath = @"C:\Users\user\Desktop\Doc Offices XML\earth_Instance.docx"; //create copy of template so that we don't overwrite it File.Copy(docTemplatePath, docOutputPath); Console.WriteLine("Created copy of template ..."); //stand up object that reads the Word doc package using (WordprocessingDocument doc = WordprocessingDocument.Open(docOutputPath, true)) { //create XML string matching custom XML part string newXml = "<root>" + "<Earth>Outer Space</Earth>" + "</root>"; MainDocumentPart main = doc.MainDocumentPart; main.DeleteParts<CustomXmlPart>(main.CustomXmlParts); //MainDocumentPart mainPart = doc.AddMainDocumentPart(); //add and write new XML part CustomXmlPart customXml = main.AddCustomXmlPart(CustomXmlPartType.CustomXml); using (StreamWriter ts = new StreamWriter(customXml.GetStream())) { ts.Write(newXml); } //closing WordprocessingDocument automatically saves the document } Console.WriteLine("Done"); Console.ReadLine(); }
相關問題
- 1. C#使用OpenXml填充單詞模板
- 2. 如何使用c填充單詞模板#
- 3. 動態填充ASP.Net使用jQuery MVC3
- 4. 如何使用ASP.NET,VB或C#填充Excel模板?
- 5. 在模板中呈現填充表單
- 6. ASP.Net MVC3 Html.PasswordFor不填充
- 7. 如何從Excel中的LOOKUP函數填充單詞模板
- 8. 使用空格填充單詞以填充單元格
- 9. 在ASP.NET MVC3中使用顯示標記填充DropDownListFor
- 10. 在MVC3中填充DropDownList?
- 11. 填充Moustache.js模板
- 12. 來填充MVC3
- 13. 使用Django模板填充json到html
- 14. 使用數組來填充Handlebars模板
- 15. 使用jQuery加載和填充模板
- 16. Word模板,填充字段,C#.NET
- 17. ASP.Net MVC3/4多個模板
- 18. C#ASP.net使用ImageButton填充GridView
- 19. 在asp.net中填充
- 20. 使用JavaScript/Knockout下拉菜單中的選定值填充MVC3視圖模型?
- 21. 未填充列表的MVC3編輯器模板
- 22. wxPython:在子面板中填充菜單
- 23. MVC3 - 在模態表單提交後使用Ajax重新填充下拉列表
- 24. MVC3 - DropDownListFor不填充
- 25. 使用C#/ Java/Visual Basic來填充Word 2007模板
- 26. 幫助自動化從Excel中填充單詞模板的過程
- 27. 使用C#EPPLUS庫填充SERFF模板XLSM文件?
- 28. 使用ViewModel填充Telerik網格(MVC3)
- 29. 填充在RichTextBox的兩個詞C#
- 30. 無法填充ASP.NET中繼器模板中的RadioButtonList
很酷。我也發現[這個鏈接](http://seroter.wordpress.com/2009/12/23/populating-word-2007-templates-through-open-xml/)非常有用。但仍然沒有得到它的工作,因爲[這](http://stackoverflow.com/questions/9433332/open-xml-sdk-2-0):( – 2012-02-24 15:33:30