首页 文章

html转换为嵌入图像的Excel

提问于
浏览
2

我有html表的html文件,嵌入图像使用标签[img src =“data:image / png; base64,] . 我想将它转换为excel,图像列显示实际图像 . 当我打开这个在excel中的html文件,表格显示正常,但图像显示为红色十字架占位符,如图所示
Excel import with embedded image

有没有办法将这个base64编码的图像转换为在excel单元格中显示?

问候

2 回答

  • 1

    使用 mime 类型将起作用 . 这是一个例子:

    ------BOUNDARY_1502961982957--
    Content-Location: file:///tmp/1502961982957/main.files/1502961983076.png
    Content-Transfer-Encoding: base64
    Content-Type: image/png
    
    iVBORw0KGgoAAAANSUhEUgAAAQQAAAEsCAYAAAAl981RAA...
    
  • 1

    彼得上面的答案更新 . 我花了一个小时左右的时间来弄清楚如何处理这个问题 . 以下是如何构建html文件的示例:

    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary="12345"
    
    --12345
    Content-Type: image/jpg;name="logo.jpg"
    Content-Transfer-Encoding: base64
    Content-ID: <logo.jpg@site.com>
    
    /9j/4QAYRXhpZgAASUkqAAgAAAAAAAA...
    --12345
    Content-Type: text/html; charset="utf-8"
    
    <html>
        <!-- Your HTML -->
        <!-- Somewhere in the HTML, replace your images with this, matching the content-id you created above -->
        <img width="your width" height="your height" src="cid:logo.jpg@site.com" />
    </html>
    --12345--
    

    对于多个图像,可以多次执行此操作,只需使用不同的名称/内容ID . 你必须在最后有一行,以便它也可以工作 .

相关问题