在 VF 页面中导出 Excel - 使用动态图像时图像未显示 URL

Export Excel in VF Page - Image not getting displayed while using dynamic image URL

我正在将 VF 页面导出为 Excel 文档。当我导出 excel 文件时,图像单元格包含空白数据。下面是我的 VF 页面代码。如果我使用静态 url (<img alt="Image" src="https://myorgurl/resource/DefaultProfileImage" />) 而不是动态图像 url.

,它工作正常
<apex:page controller="Users_Profile" contentType="application/vnd.ms-excel#Users.xls">
<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
    <thead>
        <tr>
            <th>Profile Image</th>
            <th>Name</th>
            <th>City</th>
            <th>State</th>
        </tr>
    </thead>
    <tbody>
        <apex:repeat value="{!lstUsers}" var="user">
            <tr>
                <td>
                    <image alt="Image" src="{!BaseUrl}{!URLFOR($Resource.DefaultProfileImage)}" />
                </td>
                <td>{!user.Name}</td>
                <td>{!user.City__c}</td>
                <td>{!user.State__c}</td>
            </tr>
        </apex:repeat>
    </tbody>
</table>

我已尝试在 VF 页面中使用 XML 结构而不是 HTML 标签来解决此问题,但它不起作用。

仅当 "browser" 已成功登录到 Salesforce 时,静态资源才会显示正常。我的意思是想一想,https://eu1.salesforce.com/resources/DefaultProfileImage 这样的 link 没有什么全球独一无二的。 Excel 下载图片失败。在隐私浏览(隐身模式)中转到您的图像 url,在您登录之前它不会显示 OK。这类似于使用资源的电子邮件模板或生成带有图像的 PDF 的 VF 页面。

您需要将图像上传到文档(切换到 SF Classic UI),勾选 "externally available image" 复选框,生成的 link 将看起来像 https://instance.content.force.com/servlet/servlet.ImageServer?id=015...&oid=00D...。这是全球唯一的,它包含您的组织 ID 和文档记录的 ID。

您还可以将图像上传到其他地方(Heroku?),在 Salesforce 或社区中创建站点并将其引用为 public url 之类的...基本上任何制作图像的东西无需登录即可使用。

同意Eyescream的回答。除此之外,您还可以创建 'Externally Available Image' 文档并在其中上传您的图片。现在您无需登录 salesforce 即可访问您的图像。

使用以下步骤创建文档。

  1. 转到 salesforce 中的“文档”选项卡
  2. 点击'New Document'
  3. 填写文档名称和其他详细信息
  4. Select 复选框 'Externally Available Image'
  5. 上传图片并点击保存按钮

您将获得图片预览,您可以在 salesforce 外部使用该图片 url。