+ Start a Discussion
PrazPraz 

exporting data from visualforce page to excel

Hi,

 

I have made a visualforce page which displays a table of data. I have also put some filters there for which the number of rows of the data in the visualforce page varies.

 

Now I want a mechanism in place by which I can export the data showing at a partcular moment can be exported to a excel sheet/csv with column headers which can be saved locally.

 

a help and a guideline will be much appreciated.

 

cheers

 

Praz

Best Answer chosen by Admin (Salesforce Developers) 
Jeremy.NottinghJeremy.Nottingh

I don't know if this is the only way to do it, but I have several CSVs that are created for similar purposes. The file itself is just a Visualforce page with one field displayed: a comma-separated string with my data in it. Here's the page code:

 

 

<apex:page standardController="Shipment__c" 
	extensions="myext" 
	showheader="false"
	contenttype="text/csv#{!fedexCSVfilename}" 
	cache="true">
{!DocAddresslines}

</apex:page>

 

 

See if that gets you started.

 

Jeremy

All Answers

Jeremy.NottinghJeremy.Nottingh

I don't know if this is the only way to do it, but I have several CSVs that are created for similar purposes. The file itself is just a Visualforce page with one field displayed: a comma-separated string with my data in it. Here's the page code:

 

 

<apex:page standardController="Shipment__c" 
	extensions="myext" 
	showheader="false"
	contenttype="text/csv#{!fedexCSVfilename}" 
	cache="true">
{!DocAddresslines}

</apex:page>

 

 

See if that gets you started.

 

Jeremy

This was selected as the best answer
PrazPraz

Hi Jeremy,

 

can u here give that page and the class in details like what will be the role of variable !fedexCSVfilename and !DocAddresslines

 

Regards 

 

Praz

 


PrazPraz

My requirement is to have a button and once I click it it will prompt me to save an excel sheet containing the details of the page. I don't want to generate any excel when the visualforce page is getting loaded!!

 

cheers

 

Praz

PrazPraz

It's done thank you Jeremy...contenttype attribute is the key :)

Apex Code DevelopmentApex Code Development

Hi...

 

My requirement is: 

 

I have made a visualforce page which displays a table of data. I have also put some drop down fields there and when we select all those field values and click on "Show" button the table of data will be displayed.And there should be an "Export" button.When we click on "Export" button,the entire table of data should be exported into Excel.

 

I don't want this option when the visualforce page is loading.

 

 

I would be very thankful to you if you come up with a solution.

 

Thanks!

Jagadeesh K.

Jeremy.NottinghJeremy.Nottingh

Just to clarify:

 

The page code I posted above is basically the CSV file itself. Your page, with the dropdowns, would have a button on it that calls my posted page. That will be your "Download CSV File" button.

 

Jeremy

BakulBakul

Hi, I am able to write the VF page that shows popup to download the file with the data I have set as html table.

It also downloads xls file correctly from Firefox and when opened contains correct data.

 

But I am facing trouble while opening file using IE8.

It always show the message "Internet Explorer cannot download <pagename> from c.cs4.visaul.force.com......Internet explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later".

 

My investigation tell me that there are two HTTP headers that may be causing issue.

 Pragma: no-cache
Cache-control: no-cache,max-age=0,must-revalidate

 

But I am not sure how to get rid of this errors from the page that has content type for xls download.

I tried doing

PageReference p = PageReference.<nextpage>;

p.getHeaders().clear()

 

But this had no impact.

 

Any help will be highly appreciated.

VishalAscVishalAsc

Any solution to the problem mentioned above?