+ Start a Discussion
Naresh Krishna.ax1176Naresh Krishna.ax1176 

Create excel document with multiple sheets ?

Hi All,

 

Is there any way to create excel document which contains multiple sheets ?

 

Thanks.

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

----------------- vf page----------------

<apex:page id="pg" standardStylesheets="false" controller="ControllerClass" contenttype="application/vnd.ms-excel#MultiSheetExcel.xls">

{!xmlheader}

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"

  xmlns:o="urn:schemas-microsoft-com:office:office"

  xmlns:x="urn:schemas-microsoft-com:office:excel"

  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"

  xmlns:html="http://www.w3.org/TR/REC-html40">

  <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

      <Author></Author>

      <LastAuthor></LastAuthor>

      <Company></Company>

      <Version>11.6360</Version>

  </DocumentProperties>

 

  <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">

    <WindowHeight>8535</WindowHeight>

    <WindowWidth>12345</WindowWidth>

    <WindowTopX>480</WindowTopX>

    <WindowTopY>90</WindowTopY>

    <ProtectStructure>False</ProtectStructure>

    <ProtectWindows>False</ProtectWindows>

  </ExcelWorkbook>

 <Styles>

        <Style ss:ID="Default" ss:Name="Normal">

            <Alignment ss:Vertical="Bottom"/>

            <Borders/>

            <Font/>

            <Interior/>

            <NumberFormat/>

            <Protection/>

        </Style>

        <Style ss:ID="s23">

          <Font x:Family="Swiss" ss:Bold="1"/>

        </Style>

        <Style ss:ID="s22">

          <Alignment ss:Vertical="Bottom" ss:WrapText="1"/>

        </Style>

  </Styles>

 

  <Worksheet ss:Name="First Sheet">

    <Table ss:ExpandedColumnCount="25">

        <Column ss:Width="150"/>

     

       

    <Row ss:StyleID="s23">

        <Cell><Data ss:Type="String"><apex:outputText escape="false" value="{!HTMLENCODE("Column Header")}"/></Data></Cell>

    </Row>

 

 

 <!-- Repeat and create data rows -->

    <!--<apex:repeat value="{!lstData1}" var="row">-->

      <Row>

        <Cell ss:StyleID="s22"><Data ss:Type="String"><apex:outputText escape="false" value="{!HTMLENCODE(row.acqOpp.Name)}"/></Data></Cell>

      </Row>

    <!--</apex:repeat>-->

     </Table>

  </Worksheet>

  <Worksheet ss:Name="Second Sheet">

    <Table ss:ExpandedColumnCount="12"  >

          <Column ss:Width="150"/>

    <Row ss:StyleID="s23">

        <Cell><Data ss:Type="String"><apex:outputText escape="false" value="{!HTMLENCODE(Column Label)}"/></Data></Cell>

    </Row>

 

 <!-- Repeat and create rows-->

    <!-- <apex:repeat value="{!lstData2}" var="row">-->

    <Row>

     <Cell ss:StyleID="s22"><Data ss:Type="String"><apex:outputText escape="false" value="{!HTMLENCODE("SampleValue")}"/></Data></Cell>

    </Row>

    <!--</apex:repeat>-->

 

   </Table>

 

  </Worksheet>

 

  </Workbook>

<apex:outputText value="{!endfile}" escape="false"/>

</apex:page>

 

 

------------ apex class ----------------

 

public without sharing class controllerClass{

  public string xmlheader {get;set;}

  public string endfile{get;set;}

 

  //-------------------------------------------------------------------------------------------------------------------------------

  //Constructor

  //-------------------------------------------------------------------------------------------------------------------------------

  public controllerClass() {

    //VF page gives some issues directly using the below code there, so wrap up in variable

    xmlheader ='<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?>';

    endfile = '</Workbook>';

 

  }

 

}

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Naresh Krishna.ax1176Naresh Krishna.ax1176

I couldnt able to save the page as getting below error:

 

Error: Unknown property 'controllerClass.row'

 

Could you please help me

SoulkeeperSoulkeeper

I'm getting the same error too.. how do we fix this?