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

标签 excel salesforce apex visualforce

我正在将 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 标记来解决这个问题,但它不起作用。

最佳答案

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

您需要将图像上传到 Documents(切换到 SF Classic UI),勾选“外部可用图像”复选框,生成的链接将类似于 https://instance.content.force.com/servlet/servlet.ImageServer?id=015...&oid=00D... .这在全局范围内是独一无二的,它包含您的组织 ID 和文档记录的 ID。

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

关于excel - 在 VF 页面中导出 Excel - 使用动态图像 URL 时图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62443929/

相关文章:

javascript - 在加载的网页上点击 anchor 标记按钮,然后使用 vba 点击“确定”按钮

excel - 动态更改下拉列表中一个月的天数

salesforce - Salesforce 中的 APEX 是否支持 SWITCH 和 CASE 语句?

javascript - ReactJs 中的 ApexCharts 条形图垂直类别逻辑?

c# - 转换 asp :Table to excel format

excel - 使用单元格值作为变量在 Excel 中插入方程(方程编辑器)

salesforce - 为开发人员获取 Netsuite 沙箱

http - 如何在 Http 请求的 multiPart/form-data 中写入 bool 参数

json - 如何使我的 Apex 类返回或 "run"JSON?使用 APEX REST

android - Salesforce MobileSDK : The Rest API is not enabled for this Organization