6

I have generated a excel from a VF page as below. When I download it in Desktop and open it through excel it launches fine in MS Excel except that it throws an error-"File you are trying to open - SalesforceExport.xls is in a different format than specified by the file extension.Do you want to open the file now". When I try to open the same page in Mobile, it downloads the file but when I try to open it in excel it says-"Something went wrong and your file can't be opened now. please try again". I am using MS Excel app to open it in Mobile.Please advise

<apex:page controller="ReportService" contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true">
<apex:pageBlock >
<apex:pageBlockTable value="{!cfrSummaryReport}" var="report">
    <apex:column value="{!report.QuoteNum__c}"/>
    <apex:column value="{!report.Status__c}"/>
    <apex:column value="{!report.OrderNum__c }"/>             
</apex:pageBlockTable>
</apex:pageBlock>

1
  • I suspect that the error I encountered in Desktop has got to do something with it.Not sure what is the issue though
    – Suneel
    Jun 24, 2015 at 21:18

1 Answer 1

4

While the documentation in How to export data in Excel or PDF format using Visualforce says to create an Excel file from a Visualforce page all you need to do is set the contentType to application/vnd.ms-excel, it isn't really telling the whole story.

That will indeed prompt the browser to treat the page content as an Excel spreadsheet.

However, the content is actually still HTML (Excel Web Page support). If you save the results and open it in the text editor of your choice you will see that it starts with a <script> tag.

enter image description here

An actual xlsx file is actually a zip file, so it would start with the zip PK header.

Excel on the desktop is tolerant enough (with the prompt) to read the HTML in as a spreadsheet.

The mobile version your using doesn't appear to support this.

I'd suggest exporting as a CSV in this case, as the support will be more universal.


As you commented. The Knowledge Article Content type XLS not supported in Mobile browsers covers the same points.

2
  • 1
    Thanks @Daniel for the pointer. I noticed script in the excel and tried csv format as well. But when I tried csv format, I was using apex:dataList to display the table and it was producing html <li> tags. Now I used apex:repeat and its looking good. This works in both mobile and Desktop as well. Thanks Again!
    – Suneel
    Jun 25, 2015 at 17:37
  • 1
    There is a knowledge article explaining the same - help.salesforce.com/apex/…
    – Suneel
    Jun 25, 2015 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .