I want to Implement export to excel functionality in salesforce apex with Visual force page. I want to export to excel with multiple sheet/tabs. Sheet/tab would be dynamic. There are multiple datatable/grid is available I have to export each data table to different sheet. How can I achieve this?
<apex:repeat value="{!MenuRepeat}" var="main">
<Worksheet ss:Name="{!main.SourceSetupValueType__c}">
<Table x:FullColumns="1" x:FullRows="1">
<Column ss:Width="160"/>
<Column ss:Width="160"/>
<Column ss:Width="160"/>
<Row>
<Cell ss:StyleID="Headers"><Data ss:Type="String">Property Name</Data></Cell>
<Cell ss:StyleID="Headers"><Data ss:Type="String">Source Master Source</Data></Cell>
<Cell ss:StyleID="Headers"><Data ss:Type="String">Source Value</Data></Cell>
</Row>
<apex:repeat value="{!Result}" var="res">
<Row>
<Cell><Data ss:Type="String">{!res.SourcePropertyName__c}</Data></Cell>
<Cell><Data ss:Type="String">{!res.SourceMasterSource__c}</Data></Cell>
<Cell><Data ss:Type="String">{!res.SourceSetupValueName__c}</Data></Cell>
</Row>
</apex:repeat>
</Table>
</Worksheet>
</apex:repeat>
My Controller code is here:
public String xlsHeader
{
get
{
String strHeader = '';
strHeader += '<?xml version="1.0"?>';
strHeader += '<?mso-application progid="Excel.Sheet"?>';
return strHeader;
}
}
public List<AH_DS_SetupValue_Mapping__c> getMenuRepeat()
{
lstSetupvalueMenu = new List<AH_DS_SetupValue_Mapping__c>();
List<AggregateResult> ResultData = new List<AggregateResult>();
ResultData = [SELECT Count(Id),SourceSetupValueType__c,ProjectId__c FROM AH_DS_SetupValue_Mapping__c where ProjectId__c =: PropertyNameSelectedValue Group by SourceSetupValueType__c,ProjectId__c Order by SourceSetupValueType__c ASC];
for(AggregateResult a : ResultData) {
AH_DS_SetupValue_Mapping__c sv = new AH_DS_SetupValue_Mapping__c();
sv.SourceSetupValueType__c = String.valueOf(a.get('SourceSetupValueType__c'));
sv.ProjectId__c = String.valueOf(a.get('ProjectId__c'));
lstSetupvalueMenu.add(sv);
}
System.debug('lstSetupvalueMenu.size() ' +lstSetupvalueMenu.size());
for(Integer j=0; j< lstSetupvalueMenu.size(); j++)
{
string strQuery='' ;
strQuery = 'SELECT SourceMasterSource__c,SourcePropertyName__c,SourceSetupValueName__c,TargetSetupValueId__c,TargetSetupValueMasterSource__c,TargetSetupValueName__c FROM AH_DS_SetupValue_Mapping__c WHERE ProjectId__c = ' +'\'' + lstSetupvalueMenu[j].ProjectId__c + '\'' + ' AND SourceSetupValueType__c = ' +'\'' + lstSetupvalueMenu[j].SourceSetupValueType__c + '\'' + ' Order by SourceSetupValueType__c ASC';
System.debug('strQuery ' +strQuery);
Result = Database.query(strQuery);
}
return lstSetupvalueMenu;
}
Here,I use two repeater but when I export that data In every sheet it's display last setup value data. It's overwrite data in every sheet.