Development

HowToExportTabularData

You must first sign up to be able to contribute.

Version 1 (modified by francois, 12 years ago)
creation

Symfony Howto: Export tabular data to a csv file?

I have a mymodule/myaction that outputs csv (i.e. tabular data separated by ;). If I want to point to it and have my users open it with Excel as a spreadsheet, I need to do a few things:

  • add a special routing rule for mymodule/myaction which specifies a custom suffix
export_excel:
  url:    /export.csv
  param:  {module: mymodule, action: myaction}
  • if I use mod_rewrite, add a new rule to the .htaccess to ignore the .csv files
RewriteCond %{REQUEST_URI} !\.csv$
  • declare the mymodeule/myaction view with a special content-type in the view.yml
myactionSuccess:
  has_layout: off
  http_metas:
    content-type: application/msexcel