Difficulties with generating an Excel sheet to Mac in Salesforce

By | October 16, 2015

Salesforce supports developers greatly with including an export functionality for Visualforce pages. In order to generate the Excel sheet, developers need to have a Visualforce beginning, such as the following:

Then you need to simply define the content of the Visualforce page and when it is opened, the file is downloaded. Sounds easy, right? When you are working with Microsoft Excel for Windows, then it is indeed. However Excel for Mac does not display the sheet correctly.

For our Management by Objectives (MbO) application, we wanted to give users the possibility to export their views. We thought we were finished, until we tested this on a Mac:

Bad Excel sheet for Mac

This seemed inexplicable at first, but when we take a deeper look into the first line of the Manager column, we find

This seemed familiar. So we were asking ourselves, what Javascript code does in an Excel sheet. When opening the Excel sheet with a text editor, we found out that Salesforce is actually generating a normal HTML file.

Excel sheet is in fact an HTML file

After some Google search, we found out that the use of tags, such as apex:pageBlock or apex:pageBlockTable are not compatible with the Mac version of Excel. This is because it generates a Javascript block, when one of these tags is used. We replaced these tags, as they have a formatting purpose, and used the apex:dataTable tag for displaying our data. Still the same problem. apex:dataTable produces the same bug.

Therefore we drastically removed all apex:dataTable tags with a simple HTML table and an apex:repeat instruction:

Here is a list of working <apex:Tag> tags, which do not create a Javascript block. We use these for the MbO Excel sheet:

  • <apex:outputpanel>
  • <apex:outputtext>
  • <apex:page>
  • <apex:pageMessages>
  • <apex:repeat>

And it looks great on Excel for Mac, too:

Nice Excel sheet for Mac

Leave a Reply

Your email address will not be published. Required fields are marked *