function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
justin_sfdcjustin_sfdc 

Blob value to display in Visualforce Page or Download as excel

Hi there,

I am retreiving binary Excel value from webservice callout which I managed to convert to blob. It works fine if I create a document for this value like this;
        blob image = res.getBodyAsBlob();
        Document d = new Document();
        d.name = 'CustomerByLocationFile.xls';
        d.body = image;
        d.folderId = UserInfo.getUserId();
        insert d;
        system.debug(d.id);
Now,
I want to be able to display this same file in the VisualForce page or make it download in Excel format;
I have tried using the attribute; contenttype="application/vnd.ms-excel#CustByLocation.xls" in the page tag, which downloads the excel file but it is in not Readable format.

If someone could please help me out on displaying these properly in excel download or even in VFpage that would be of great help.

Thanks in advance!

logontokartiklogontokartik
You can try using the OutputLink by getting the Document Id. 
      <apex:outputLInk value="https://c.na15.content.force.com/servlet/servlet.FileDownload?file={!d.Id}" target="_blank">Download File</apex:outputLink>
justin_sfdcjustin_sfdc
Hi Kartik,

Sorry on the delayed response.
I might have put the question in incorrect order.

Actually my approach is: On click of the button, I am doing a REST callout, which returns me blob value. I want to display this into the VF page. The blob value I am getting in return is a binary excel file.

Would you know how to resolve this?
Thanks!
SidharthSidharth
Hi Justin. I am stuck on the same requirement. In case you have find the solution, please share. Thanks.
justin_sfdcjustin_sfdc
Hey Sidharth,

Sorry for the late response. I did resolve this issue. What I had to do was convert the blob into attachment and displayed in that way to the users.
Let me know if I can be of any help.

Thanks!
SidharthSidharth
Hi Justin,

Thanks for the reply. What i am doing right now is getting the blob value from api response, and providing a download link for it in a vf page. Exaplined link : https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AY1qIAG

Also, alternatively i can save the blob value as an attachment in sf, but not sure how to display the excel file into vf page? Is that something possible ?

Thanks
Sid