【发布时间】:2011-06-03 17:11:51
【问题描述】:
我有一个 vb.net 网络应用程序,我需要让我的用户能够下载 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
...但我不知道如何使文本变为粗体或创建表格。我相信有更好的方法。
【问题讨论】:
-
查看here 以获取有关如何在 ASP.NET 中创建真实文字文档的更多信息。
-
一些关于为什么这个问题被标记下来的线索会很好。