0

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?

1

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.

  • Ok, i already have the controller that queries Attachments to render them on the VF page. So is it right I should create a document for each of queried attachmnet , insert it and then use it Id in URL on the page? In thiat case, can i use it in wy i alredy have - inside the repeat tag, and what Url i shuld use instead content.force.com/servlet/servlet.FileDownload?file ? – Igor H Dec 26 '14 at 7:02
  • Amyway, it does not work. I still have an arror message instead of picture – Igor H Dec 30 '14 at 14:03
-2

So, after a days of braincrushing, I have found the solution.

  1. Creating document from attachment

public Document createDocument(Attachment A){

    Document currentDoc = new Document();

    currentDoc.AuthorId = UserInfo.getUserId();
    currentDoc.FolderId = '00lb0000000N4fs';
    currentDoc.Body = A.Body;
    currentDoc.Name = A.Name;
    currentDoc.Description = A.ParentId;
    currentDoc.IsPublic = true;

    return currentDoc;


}
  1. Then, when IsPublic = true we can see piscture content right on the standard document's page. Right click on this image - > copy picture URL. Then just paste this URL into some text editor to see. In my case it looks like this

    https://c.cs18.content.force.com/servlet/servlet.ImageServer?id={!doc.DocumentItem.Id}&oid=00D110000008DG8&lastMod=1419949541000

  • Hmmmm...Seems to be the output of what I told you to do in my answer...... – Eric Dec 30 '14 at 16:44
  • Actually, yes. But its not obvoius for me how it looks like :) I mean URl . – Igor H Dec 31 '14 at 8:50
  • You came up with your final code due to an answer given by someone on this site. SFSE it NOT here to write code for you. It is here to provide you assistance so you CAN get to that final point. If you keep asking questions and posting your own results as answers you will find quickly that people will be unwilling to help you. Not because we did not get the 24 pts, but because it shows that you fail to see what this site is about. Cheers – Eric Dec 31 '14 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.