You need to sign in to do that
Don't have an account?
Mohan t 7
Export Vf to excel but avoid button from that page ?
I am facing an issue when exporting visual force page data as excel. As it exporting whole page ......The problem was like i have vf page with title and button...so when i click the button the data in pageblock table should download. but it download including button as well . how to avoid button on page or how to download only pageblock table data.
VF code --
<apex:page Standardcontroller="Account" extensions="accNotes" standardStylesheets="false" contentType="{!IF(isExport = true, 'application/vnd.ms-excel#contacts.xls', '')}" cache="true">
<apex:form >
<apex:pageBlock id="pgb">
<apex:pageBlockSection columns="8" >
<apex:outputPanel layout="block">
<b><apex:outputLabel style="margin" value="Notes & Attachments"></apex:outputLabel></b>
<apex:commandButton id="button" style="margin-left:80px;" value="Export as Excel" action="{!exportToExcel}" reRender=""> /////**** This is also printing on excel page when downloaded******************///
</apex:commandButton>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!Recordsall}" var="n">
<apex:column style="overflow:hidden;white-space:nowrap" value="{!acc.AccountNumber}">
<apex:facet name="header">Account Number</apex:facet>
</apex:column>
<apex:column style="overflow:hidden;white-space:nowrap" value="{!acc.name}">
<apex:facet name="header">Account Name</apex:facet>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
VF code --
<apex:page Standardcontroller="Account" extensions="accNotes" standardStylesheets="false" contentType="{!IF(isExport = true, 'application/vnd.ms-excel#contacts.xls', '')}" cache="true">
<apex:form >
<apex:pageBlock id="pgb">
<apex:pageBlockSection columns="8" >
<apex:outputPanel layout="block">
<b><apex:outputLabel style="margin" value="Notes & Attachments"></apex:outputLabel></b>
<apex:commandButton id="button" style="margin-left:80px;" value="Export as Excel" action="{!exportToExcel}" reRender=""> /////**** This is also printing on excel page when downloaded******************///
</apex:commandButton>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!Recordsall}" var="n">
<apex:column style="overflow:hidden;white-space:nowrap" value="{!acc.AccountNumber}">
<apex:facet name="header">Account Number</apex:facet>
</apex:column>
<apex:column style="overflow:hidden;white-space:nowrap" value="{!acc.name}">
<apex:facet name="header">Account Name</apex:facet>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
What is the need of the button in the vfpage if you have already mention the content type attribute in <apex:page > component.
just remove the button and check it once. when ever the page relaods the content will gets download in the excel sheet.
thanks & regards
Srikanth