将网页另存为Word文档? (VB.NET)

发布于 2024-07-30 10:52:50 字数 764 浏览 1 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溇涏 2024-08-06 10:52:50

Word 会很高兴地打开一个扩展名为 .doc 的 HTML 文件。

Word will open a HTML file with the extension .doc happily enough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文