将网页另存为Word文档? (VB.NET)
我正在尝试在 vb.net 中创建 Word 文档。 由于服务器上的权限问题,我无法使用 COM Word.Application 方法。 所以我用 HTML 重新创建了 WORD 文档,并尝试更改内容类型并仅输出 HTML
它工作正常。 它输出 HTML 并打开包含内容的只读文件的 word。 然而,当我点击“另存为”时,它想要另存为 HTML 文档,即使它在 Word 中将其打开为 file.doc。
有没有办法解决这个问题,使其首先选择 .doc?
Response.Clear()
Response.AddHeader("content-type", "application/msword")
Response.AddHeader("content-disposition", "inline; filename=" & "file.doc")
Response.Charset = ""
Dim strPath As String = Request.PhysicalApplicationPath & "MainTemp2.html"
Dim fStream As New FileStream(strPath, FileMode.Open, FileAccess.Read)
Dim sReader As New StreamReader(fStream)
Dim strData = sReader.ReadToEnd()
sReader.Close()
Response.Write(strData)
Response.End()
预先感谢您的帮助。
I'm trying to create a Word document in vb.net. I can't use the COM Word.Application method due to permission issues on the server. So i've recreated the WORD document in HTML and tried to change the content-type and just output the HTML
It works 'ok'. It outputs the HTML and opens up word with a read-only file with the content in there. However when i hit 'save as' it wants to save as a HTML document even though its opened it in word as file.doc.
Is there a way to fix that so it selects .doc first?
Response.Clear()
Response.AddHeader("content-type", "application/msword")
Response.AddHeader("content-disposition", "inline; filename=" & "file.doc")
Response.Charset = ""
Dim strPath As String = Request.PhysicalApplicationPath & "MainTemp2.html"
Dim fStream As New FileStream(strPath, FileMode.Open, FileAccess.Read)
Dim sReader As New StreamReader(fStream)
Dim strData = sReader.ReadToEnd()
sReader.Close()
Response.Write(strData)
Response.End()
Thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Word 会很高兴地打开一个扩展名为 .doc 的 HTML 文件。
Word will open a HTML file with the extension .doc happily enough.