Generate Excel sheet with a dynamic name in visualforce

In visualforce we can get the output in excel form by specifying the content type in the page component. By specifying the content type as 'application/' the viusalforce will always be rendered as excel sheet.

As an example below visualforce page will give an output of excel sheet with the name of the sheet being 'myexcelreport'

Visualforce Page

Apex Class

In this case the name of the sheet will remain static and every time you extract the sheet it will be named as 'myexcelreport'. At times we may need the excel sheet name that changes every time with certain criteria's for example date. That is we may need the name of the excel sheet be dynamic as per our requirements. We can achieve this by simply concatenating the formula in contenttype attribute with curly bracket and ! as done in below example-

Apex Class
In this case the output excell sheet will have name depending on the date, ex- 'Report- 08_12_2014'

1 comment: