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
Greg RohmanGreg Rohman 

Excel XML messaging attachment - some nodes being commented out?

Hello.

I have a Visualforce component called "Rpt_MonthlyExpenseSummary_Excel" that outputs an Open Office XML file that opens properly in Excel with all formatting, formulas, named ranges and other items intact intact. When I embed this component on a simple page and access it via a browser, it prompts me to download the file, and everything functions properly. Here's a snippet of the VF page where I am including the component, and the XML contained in the downloaded file it generates:
 
<apex:page controller="CtrlRptMonthlyExpenseSummary" standardStylesheets="false" contenttype="application/vnd.ms-excel#TestExport_{!TODAY()}.xml">
    <c:Rpt_MonthlyExpenseSummary_Excel />
</apex:page>
Output:
<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel">
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"></Alignment>
   <Borders></Borders>
   <Font ss:Color="#000000" ss:FontName="Calibri" ss:Size="12" x:Family="Swiss"></Font>
   <Interior></Interior>
   <NumberFormat></NumberFormat>
   <Protection></Protection>
  </Style>
  <Style ss:ID="sCurrency">
   <NumberFormat ss:Format="$#,##0"></NumberFormat>
   <Borders>
    <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"></Border>
    <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"></Border>
    <Border ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="1"></Border>
    <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"></Border>
   </Borders>
  </Style>

I also attaching this same Excel file to an email template using <messaging.emailTemplate>:
 
<messaging:emailTemplate subject="Report: Monthly Expense Summary" recipientType="User">
    <messaging:htmlEmailBody >
            Omitted stuff here
    </messaging:htmlEmailBody>
    <messaging:attachment filename="Report: Monthly Expense Summary - {!MONTH(TODAY())}-{!YEAR(TODAY())}.xls" >
        <c:Rpt_MonthlyExpenseSummary_Excel />
    </messaging:attachment>
</messaging:emailTemplate>
The tempate functions correctly as well, and the attachment is included. The issue, though, is that portions of the XML file, namely the formatting and styles that I have defined, are being commented out with <!-- and //--> tags. Here's a relevant snippet of the attachment XML file:
<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel">
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
<!--
   <Alignment ss:Vertical="Bottom"></Alignment>
   <Borders></Borders>
   <Font ss:Color="#000000" ss:FontName="Calibri" ss:Size="12" x:Family="Swiss"></Font>
   <Interior></Interior>
   <NumberFormat></NumberFormat>
   <Protection></Protection>
//-->
</Style>
  <Style ss:ID="sCurrency">
<!--
   <NumberFormat ss:Format="$#,##0"></NumberFormat>
   <Borders>
    <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"></Border>
    <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"></Border>
    <Border ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="1"></Border>
    <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"></Border>
   </Borders>
//-->
</Style>

I cannot figure out why everything functions properly as a page, but when attached to an email, that portions of the XML file are being arbitrarily commented out. Any ideas? 

Much thanks in advance.

-Greg