简体   繁体   English

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

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

I am exporting a VF page as Excel document.我将 VF 页面导出为 Excel 文档。 While I export excel file, Image cell contains blank data.当我导出 excel 文件时,图像单元格包含空白数据。 Below is my VF page code.下面是我的 VF 页面代码。 It is working fine if I am using static url ( <img alt="Image" src="https://myorgurl/resource/DefaultProfileImage" /> ) instead of dynamic Image url.如果我使用 static url ( <img alt="Image" src="https://myorgurl/resource/DefaultProfileImage" /> )而不是动态图像 Z572D4E421E5E6B7BC112A

<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>

I have tried XML structure instead of HTML tags in VF page to get this resolved but it is not working.我已经尝试在 VF 页面中使用 XML 结构而不是 HTML 标记来解决这个问题,但它不起作用。

Static resources display OK only if the "browser" has successfully logged in to Salesforce.只有当“浏览器”成功登录到 Salesforce 时,Static 资源才会显示 OK。 I mean think about it, there's nothing globally unique in a link like https://eu1.salesforce.com/resources/DefaultProfileImage .我的意思是想一想,在https://eu1.salesforce.com/resources/DefaultProfileImage类的链接中没有什么全球独一无二的。 Excel fails to download the image. Excel 下载镜像失败。 Go to your image's url in private browsing (incognito mode), it will not display OK until you log in. This is similar to email templates that use resources or VF pages generating PDFs with images. Go 到您图像的 url 在隐私浏览(隐身模式)下,它不会显示 OK,直到您登录。这类似于 email 使用模板生成 PDF 页面的模板。

You need to upload the image to Documents (switch to SF Classic UI), tick "externally available image" checkbox and the link that's generated will look like https://instance.content.force.com/servlet/servlet.ImageServer?id=015...&oid=00D... .您需要将图像上传到 Documents(切换到 SF Classic UI),勾选“外部可用图像”复选框,生成的链接将类似于https://instance.content.force.com/servlet/servlet.ImageServer?id=015...&oid=00D... This is globally unique enough, it contains your org id and document record's id.这在全球范围内是独一无二的,它包含您的组织 ID 和文档记录的 ID。

You can also upload the image somewhere else (Heroku?), create Site in Salesforce or Community and reference it as a public url like that... Basically anything to make the image available without logging in.您还可以将图像上传到其他地方(Heroku?),在 Salesforce 或社区中创建站点并将其引用为公共 url 之类的......基本上任何使图像可用而无需登录的东西。

I Agree with Eyescream's answer.我同意 Eyescream 的回答。 In addition to it, you can create 'Externally Available Image' document and upload your image in it.除此之外,您还可以创建“外部可用图像”文档并在其中上传您的图像。 Now you can access your image without login into salesforce.现在您无需登录 salesforce 即可访问您的图像。

Use following steps to create a document.使用以下步骤创建文档。

  1. Go to Documents tab in salesforce Go 到 salesforce 中的文档选项卡
  2. Click on 'New Document'点击“新建文档”
  3. Fill Document Name and other details填写文档名称和其他详细信息
  4. Select checkbox 'Externally Available Image' Select 复选框“外部可用图像”
  5. Upload Image and Click on Save button上传图片并点击保存按钮

You will get Image preview and you can use that image url outside salesforce.您将获得图像预览,您可以在 salesforce 之外使用该图像 url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM