1

I believe I am following the correct pattern for exporting Visualforce to Excel on Mac

<apex:page controller="AccountReportConfiguratorController"  
        contentType="application/vnd.ms-excel#Report.xls" 
        standardstylesheets="false" 
        language="en-US"
        showHeader="false"
        readOnly="true"
        cache="true"
        >




        <apex:dataTable value="{! FilteredAccounts }" var="a">

                 <apex:facet name="header">{!DisplayReportName}</apex:facet>

                    <apex:column><apex:outputField value="{! a.DRC_RecordOrder__c }"/> </apex:column>

                        <apex:column>
                            <apex:facet name="header">Deal Name</apex:facet>
                            <apex:outputField value="{! a.DRC_Account__r.Name }"/> 
                        </apex:column>

On Windows it works fine on Mac it's missing the first row and outputting JavaScript like this

if(!window.sfdcPage) { window.sfdcPage = new ApexDetailPage(); 

I'm using dataTable instead of page block and have developer tools turned off.

Any advice?

Thanks

1
  • Strange problem! Maybe try setting the sidebar attribute of the page tag to false? Or checking your output for discrepancies between Windows & OS X newline characters? en.wikipedia.org/wiki/Newline
    – Rob
    Aug 11, 2015 at 0:22

3 Answers 3

2

My understanding is that none of these solutions will generate a real XLS file.

The best result we will get is an HTML file with a wrong extension (.xls), which MS Excel will read and then convert to a real XLS file.

In addition, recent versions of MS Excel are likely to show a warning message saying that the extension of the file does not match its content.

1
  • 1
    yep - this is what I have observed as well and not surprising since converting HTML into native internal Excel data structure is non trivial work
    – cropredy
    Feb 12, 2016 at 21:17
1

Try apex:outputText instead of apex:outputField

<apex:column>
    <apex:facet name="header">DRC RecordOrder</apex:facet>
    <apex:outputText value="{! a.DRC_RecordOrder__c }"/> 
</apex:column>

<apex:column>
    <apex:facet name="header">Deal Name</apex:facet>
    <apex:outputText value="{! a.DRC_Account__r.Name }"/> 
</apex:column>

1

You should completely avoid Visualforce-specific tags, such as apex:dataTable, apex:outputField, etc. They sometimes create a Javascript, which is shown in Office for Mac, but not in Office for Windows.

What I found so far is that the following apex-tags do not create any Javascript:

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

I wrote an article about this, if you want to read more about it: Excel Sheet Generation for Mac

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.