javascript - 将图像从 SQL Server 插入到 Word 文档文件

标签 javascript c# jquery asp.net vb.net

我想导出网页上显示的图像。该图像以 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/

相关文章:

jquery - 如何在提交表单后再次运行 jQuery 验证器代码?

c# - System.MethodAccessException : 'Attempt by method ' Microsoft. Extensions.Logging.Configuration 问题

javascript - 如何在 chartjs 中扩展圆环图的切片?

javascript - 为什么 Firefox 有时会生成 "console not defined"错误?

javascript - slim : $: 是什么意思?

javascript - 更新 Vuetify 但 sass loader 不起作用

Javascript 函数调用的行为不符合我的预期

C#:来自变量字符串的外部 EXE 输入/输出管道

c# - 如何让文本框超过 20 像素高?

php - 来自php的Ajax响应,在div内回显span?