如何使用ASP.Net和C#(2008)创建扩展名为.doc和.docx的word文档文件?
答案 0 :(得分:2)
我更喜欢避开com路由,而是在响应流中生成doc。这对我来说非常有效。希望它有所帮助。
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();
答案 1 :(得分:1)
请参阅以下链接
http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/
http://2leggedspider.wordpress.com/2004/06/30/creating-a-word-document-using-aspnet-and-c/
答案 2 :(得分:1)
OfficeWriter是DOC和DOCX API,针对ASP.NET使用进行了优化。您可以使用它创建两种文件格式: