从 .net Web 应用程序创建文档文件
我有一个 vb.net Web 应用程序,我需要为我的用户提供下载 ms-word .doc 文件的功能。该文件需要动态创建,并且应包含一些粗体文本和一个表格。
我遇到过这段代码,它构建了一个 .doc 文件,并让您下载它:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileName As String = "GenerateDocument" + ".doc"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName)
Dim strHTMLContent As StringBuilder = New StringBuilder()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
strHTMLContent.Append("<p align='Center'>MY CONTENT GOES HERE</p>".ToString())
HttpContext.Current.Response.Write(strHTMLContent)
HttpContext.Current.Response.End()
HttpContext.Current.Response.Flush()
End Sub
...但我不知道如何使文本加粗,或创建一个表格。我确信有更好的方法。
I have a vb.net web app, and I need to give my users the facility to download a ms-word .doc file. This file needs to be created dynamically, and should contain some bold text and a table.
I've come across this code, which builds a .doc file, and lets you download it:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileName As String = "GenerateDocument" + ".doc"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName)
Dim strHTMLContent As StringBuilder = New StringBuilder()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
strHTMLContent.Append("<p align='Center'>MY CONTENT GOES HERE</p>".ToString())
HttpContext.Current.Response.Write(strHTMLContent)
HttpContext.Current.Response.End()
HttpContext.Current.Response.Flush()
End Sub
...but I don't know how to make the text bold, or create a table. I'm sure there's a better way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很抱歉回答我自己的问题,但我刚刚遇到这个: http://www .codeproject.com/KB/office/Wordyna.aspx
它非常适合我,因为它允许 HTML 输入。所以桌子是轻而易举的事。
Sorry to answer my own question, but I've just come across this: http://www.codeproject.com/KB/office/Wordyna.aspx
It works perfectly for me, because it allows HTML input. So tables are a doddle.