如何使用VB.NET将.NET ASP:表格导出到Word 2007 .docx [英] HowTo Export .NET asp:Table to Word 2007 .docx using VB.NET

查看:125
本文介绍了如何使用VB.NET将.NET ASP:表格导出到Word 2007 .docx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Web Developer2008.我在ASP.NET中有一个asp:Table,可以将该表导出为.doc(Word 97-2003)格式.但是,当导出到Word 2007(.docx)时,使用.docx扩展名可以成功导出.该文件无法使用Word 2007打开,但可以在Word-2003中打开.尝试在Word-2007中打开时,出现一条错误消息,提示无法打开,文件内容无效"(类似).

我在这里提供的代码供您参考.

如果有人可以帮助我,请.....

提前谢谢.

I''m using Visual Web Developer 2008. I have an asp:Table in ASP.NET and I could Export that Table to .doc (Word 97-2003) formats. But when Exporting to Word 2007 (.docx), Export is success with .docx extension. That file cannot open using Word 2007, but can open in Word-2003. When trying to open in Word-2007 one Error message saying that "Cannot Open, Invalid file content" (like that).

The code I''m giving here for your reference.

If anybody can help me pls.....

Thanks in advance.

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"       
Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.docx")
Response.ContentEncoding = System.Text.Encoding.UTF7
Response.Charset = ""
EnableViewState = False

Dim writer As New System.IO.StringWriter()
Dim html As New System.Web.UI.HtmlTextWriter(writer)
Table1.RenderControl(html)
Response.Write(writer)
Response.End()

推荐答案

只需将html保存为.doc文件, Word将打开它.顺便说一句,您要使用Response.WriteFile()Response.Write().
Just save the html as a .doc file, and Word will open it. By the way, you want to use Response.WriteFile() versus Response.Write().


全部,

我通过将UTF7更改为UTF8来完成操作,从而也可以在Word2007中打开正确的.DOC文件.

非常感谢.
Hai All,

I done It by changing UTF7 to UTF8 to get Proper .DOC file openable in Word2007 too.

Thank you very much.


这篇关于如何使用VB.NET将.NET ASP:表格导出到Word 2007 .docx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆