+ Start a Discussion
srilakshmi1.387861669756762E12srilakshmi1.387861669756762E12 

click on a button visual force page will be download as a excel file

hai in my visual force page three buttons are there pdf,word,excel.when ever click on pdf the page is render as pdf,click on word that same page will be download as word file,click on excel excel file will be downloaded for that i wrote a code like this 


<apex:page standardController="account" recordSetVar="account" renderAs="{!if($CurrentPage.parameters.isPdf == null, null, 'pdf')}" contentType="{!if($CurrentPage.parameters.isWord== null, null,'application/x-excel#FileName.doc')}" extensions="pwe">
<apex:form >
<apex:pageBlock >
<apex:pageblockButtons >
<apex:commandButton value="pdf" action="/apex/automatic_insert?isPdf=true"/>
<apex:commandButton value="word" action="/apex/automatic_insert?isWord=ture"/>
<apex:commandButton value="excel" action="{/apex/automatic_insert?isExcel=ture"/>
</apex:pageblockbuttons>
<apex:pageBlockTable value="{!account}" var="a">
  <apex:column value="{!a.name}"/>
  <apex:commandButton action="{!save}" value="save"/>
  </apex:pageBlockTable>
  </apex:pageBlock>
</apex:form>
</apex:page>
 

but i am getting confusion with contentType.in <apex:page> we can place any one contentType.when how can i get excel with this code please help me ony one
Abhi__SFDCAbhi__SFDC
try this for excel -: 

contentType="application/vnd.ms-excel#PartnerDealReg.xls"
or 
contentType="text/csv#U65_{!dtdisplay}.csv


srilakshmi1.387861669756762E12srilakshmi1.387861669756762E12
i know contentType="application/vnd.ms-excel#PartnerDealReg.xls" this is for excel generation.what i am asking is in the  same page i want to write code for both word genaration and excel genaration code.
Abhi__SFDCAbhi__SFDC
Try this -: 

<apex:page standardController="account" recordSetVar="account" renderAs="{!if($CurrentPage.parameters.isPdf == null, null, 'pdf')}" contentType="{!if($CurrentPage.parameters.isWord == null, if($CurrentPage.parameters.isExcel == null, null ,'application/vnd.ms-excel#fileName.xls'),'application/x-excel#FileName.doc')}" >

Mark this as Solved if it resolves your query.
srilakshmi1.387861669756762E12srilakshmi1.387861669756762E12
fine now it is working thank you abhi
Hariom Chaudhary 1Hariom Chaudhary 1
Hey, srilakshmi can you provide apex class for it ?
mulukutla pavanimulukutla pavani
Srilakshmi can you please provide apex class for this