如何使用ASP.Net與C#(2008)創建兩個擴展名爲.doc和.docx的word文檔文件?創建Word文檔文件
回答
我寧願避免COM路線,而是產生在響應流中的文檔。這對我來說真的很好。希望能幫助到你。
Response.ContentType = "application/msword";
Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;
Response.Charset = "UTF-8";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + "mydoc.doc");
Response.Write("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>");
Response.Write("<head>");
Response.Write("<!--[if gte mso 9]> <xml> <w:WordDocument> <w:View>Print</w:View> <w:Zoom>100</w:Zoom> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml> <![endif]-->");
Response.Write("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"\"text/html; charset=UTF-8\"\">");
Response.Write("<meta name=ProgId content=Word.Document>");
Response.Write("<meta name=Generator content=\"Microsoft Word 9\">");
Response.Write("<meta name=Originator content=\"Microsoft Word 9\">");
Response.Write("</head>");
Response.Write("<body>");
Response.Write("<div class=Section2>");
// write some content here
Response.Write("</body>");
Response.Write("</html>");
HttpContext.Current.Response.Flush();
謝謝。我會檢查這一點。那麼在腳本任務編碼部分,我怎麼不能維護我爲Reference添加的文件?每當我去編輯腳本時,我都必須添加參考文件來恢復編碼。是否有其他設置用於維護添加以供參考的文件? – 2010-05-11 06:41:15
以及爲了獲得「迴應」而包含的命名空間是什麼?我沒有得到System.Web.HttpResponse !!!!!!! – 2010-05-11 06:45:29
我不遵循您的第一條評論。也許你可以進一步解釋,並有人可以提出。 至於響應,如果你從你的web表單調用它,你應該可以直接使用。奇。您可能想嘗試Page.Response或Context.Response或System.Web.HttpContext.Current.Response。 – earthling 2010-05-11 06:51:44
OfficeWriter是爲ASP.NET使用而優化的DOC和DOCX API。你可以用它創建兩種文件格式:
- 1. 創建Word文檔
- 2. Android - 創建Word文檔
- 3. 用Java創建Word文檔
- 4. 創建jpg並插入word文檔
- 5. 帶Yii的PDF或Word創建文檔?
- 6. 在word文檔中創建景觀表
- 7. 從java創建新的word文檔
- 8. 從word或pdf文檔創建報告
- 9. 使用VBA創建Word或XML文檔
- 10. 創建一個Word文檔,Swift
- 11. 在C#中創建Word文檔#
- 12. 使用OpenXml創建Word文檔(docx)
- 13. 如何在WinRT中創建Word文檔
- 14. 使用XML和C創建Word文檔#
- 15. Word Interop創建空白標籤文檔
- 16. 使用VSTO創建新的Word文檔
- 17. 使用OpenXML創建Word文檔
- 18. 格式自動創建的Word文檔
- 19. 使用C#創建Word(2013)文檔
- 20. 使用JavaScript「創建」Microsoft Word文檔
- 21. 用Open XML創建Word文檔
- 22. 用C#創建一個Word文檔?
- 23. 從代碼創建Word文檔
- 24. 上傳Word文檔創建文件下載(PHP)
- 25. 創建Word文檔時損壞的文件
- 26. 從Word 2007或OpenOffice/LibreOffice中的XML文件創建文檔
- 27. Android創建Word(doc)文件
- 28. LuaCOM Word文檔頭文件
- 29. 將Word文檔保存爲「Word文檔」
- 30. 在Word文檔中嵌入Word文檔
可能欺騙:http://stackoverflow.com/questions/2727633/how-to-open-ms-office-word-in-asp-net – ahsteele 2010-05-11 06:13:32