我想导出网页上显示的图像。该图像以 Sql 图像数据类型存储。显示图像时,我将图像转换为 Base64String。
Image1.ImageUrl = "data:image/jpg;base64," & Convert.ToBase64String(imgPhoto)
导出页面时,图像未显示在Word文档文件中。
由于安全原因,我无法在服务器上存储图像。 下面的代码用于导出到word文件。
Response.AddHeader("content-disposition", "attachment;filename=Test.doc")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/ms-word "
Response.Charset = ""
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
' Create a form to contain the grid
ControlID.RenderControl(htmlWrite)
Dim stringWrite1 As New System.IO.StringWriter()
Dim htmlWrite1 As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite1)
' Create a form to contain the grid
ImageLogo.RenderControl(htmlWrite1)
Response.Write(stringWrite1.ToString() & stringWrite.ToString())
Response.[End]()
最佳答案
您实际上并不是在创建 Word 文档,只是将 HTML 呈现为单词 MIME 类型。我不相信 word 支持 data:image 定义,因为它比 2007 年之前的 word 格式要新得多。相反,请尝试 OpenXML SDK。尽管它仅创建 Word 2007+ 文档,但大多数人都可以查看它们。 OpenXML SDK 将使您能够创建真实的文字文档并从二进制图像数据创建图像。
http://www.microsoft.com/en-us/download/details.aspx?id=30425
http://msdn.microsoft.com/en-us/library/office/bb448854%28v=office.15%29.aspx
关于javascript - 将图像从 SQL Server 插入到 Word 文档文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27078192/