+ Start a Discussion
KamindiaKamindia 

Posting Selected Data table Data in Excel from VisualForce page

Hello ,

I am trying to do some excel calculation  in Visual force page. after save that  some of the data table  need to Downloaded to Excel.sheet. Is there any possibility to export data to Excel with the whole Data table ?

 

Regards

Kam

Adam HowarthAdam Howarth

Hey,

 

I am doing something similar.

 

The way I did it, was to create a new VisualForcePage as below:

 

 

<apex:page standardstylesheets="false" controller="YourController" contentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
	<apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even"

                        styleClass="tableClass">

		<apex:facet name="caption">table caption</apex:facet>

		<apex:facet name="header">table header</apex:facet>

		<apex:facet name="footer">table footer</apex:facet>

		<apex:column>

		        <apex:facet name="header">Name</apex:facet>

			<apex:facet name="footer">column footer</apex:facet>

			<apex:outputText value="{!account.name}"/>

		</apex:column>

		<apex:column>

			<apex:facet name="header">Owner</apex:facet>

			<apex:facet name="footer">column footer</apex:facet>

			<apex:outputText value="{!account.owner.name}"/>

		</apex:column>

	</apex:dataTable>
</apex:page>

 

The important bit is contentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

 

 

So I would

 

  • Create a link that opens in a new tab to the excel page.
  • Bind the table as you are doing in your current page.
  • When the link is clicked, an xslx file will be downloaded.

 

Cheers,

Adam