I have a form whose class extends FormBase. The form has a table that gets populated with information.

Basically I'm trying to download the table into a CSV or Excel file. I've seen some old posts for Drupal 6 but I haven't found anything for Drupal 8.

How can I achieve this?


You can use the Forena module. Here is a quote from that page:

... built of the idea of using SQL to get data out of a database and use XHTML and CSS to format it into web reports.

Here is another quote from Reasons for considering Forena, related to the "CSV" in the question here:

Reports created by Forena ... can be saved (exported) as PDF documents with embedded graphs. Other supported formats for saving a report are CSV, XLS, DOC, HTML, etc.

So if you'd install Forena in your site, then these are the steps for creating such CSV files are:

  • a custom SQL query (where you have the full power of SQL at your fingertips, and various extra features related to it provided by Forena, such as using report parameters, conditional SQL, etc).
  • a custom report (either by an admin, or by just any regular user who is either familiar with creating what is called 'FRX files', or otherwise using the WYSIWYG report editor).
  • saving the report in (eg) CSV format, using one of the typical hyperlinks to do so in a report.

For an online demo (prior to installing/testing Forena), checkout these links:

Disclosure: I'm a co-maintainer of this module,
I hope this does not violate the site's policy on self-promotion.

Not the answer you're looking for? Browse other questions tagged or ask your own question.