[SalesForce] Visualforce page to Excel doc with images from attachments

I have an issue with rendering VF page as xls file.

I have an apex page with a table, wich consists of some visit data and it's attachments. Attachments has an image content type, so it looks like this

    <apex:repeat value="{!vwa.attachment}" var="att">
        <div class="set">
            <table style="width:95%;"> 
                    <tr>
                        <td> 
                           <table>
                                  <tr>
                                      <td>
                                          <div class="aa">
                                             <a href="/servlet/servlet.FileDownload?file={!att.AttachmentItem.Id}" 
                                                rel="lightbox[{!vwa.visit.Id}]" 
                                                title="Press right side of image to view next attachement or left side to view previous">
                                              <img src="/servlet/servlet.FileDownload?file={!att.AttachmentItem.Id}" style="height:100px;"/>
                                             </a>
                                            </div> 
                                        </td>
                                     </tr>   
                                     <tr>
                                          <td>
                                               <div class="aa">
                                                    <apex:outputText value="{!att.productName}" />
                                               </div>   
                                           </td>    
                                      </tr> 
                                 </table> 
                             </td>
                        </tr> 
                   </table>  
             </div> 
     </apex:repeat>

On the VF page it works perfectly, and i am using this data on another, almost the same page to export it to excel. An issue is – the images in xls file are empty, but hyperlinks works correct.

<apex:page title="Excel export page" controller="AttExcelExportController"  contenttype="application/x-msexcel#Attachments.xls"  >

is the page tag, and

<a href="https://c.cs18.content.force.com/servlet/servlet.FileDownload?file={!att.AttachmentItem.Id}" rel="lightbox[{!vwa.visit.Id}]"><img src="https://c.cs18.content.force.com/servlet/servlet.FileDownload?file={!att.AttachmentItem.Id}" border="0" align="left" alt=""/></a>

are the src's to content on my instance. Clicking empty image in excel file opens an image in a brouser, but the same src for tag gives an empty image. Can anybody tell me whats I am doing wrong? Maybe there are some server access problems ore something?

Best Answer

You cannot put images into the excel output with a download link. You need to have a static URL to use the image.

If the attachment is an image you could:

  1. Create a controller for the page
  2. Have it grab the Attachment and create a document in salesforce out of it
  3. Have the vf page output the image using the document url

Then you will have to write a batch to delete the documents on a daily basis to clean things up.

Related Topic