Removing HTML tags from DataTables Excel exports
The Excel button on a DataTables View removes the HTML tags from every cell when it builds the spreadsheet, so you don’t need any code to get plain text. The column headings come out as plain text too.
Formatted values in the Excel file #
| In the table | In the Excel file |
|---|---|
| Bold, italic or paragraphs in a Paragraph field | The text alone |
| A list, such as the choices checked in a Checkbox field | The items, separated by semicolons |
| A line break | A space |
| A link | The link text, then the address in parentheses |
| An image that opens in a lightbox | The image’s address |
| An image that doesn’t open in a lightbox | The image’s alternative text, which is the field label unless the field’s Alternative text setting holds another |
Showing URLs in DataTables Excel exports lists what each kind of link column holds.
If your Excel file shows HTML tags #
Tags in the file come from custom code that replaces the formatting the Excel button gives each cell, such as the snippet that Showing URLs in DataTables Excel exports used to give. The snippet this page used to give replaces that formatting too, and in DataTables 3.14 it leaves image columns empty and drops the addresses after links.
To remove the snippet:
- Edit your View.
- In the Settings box, click the Custom Code tab.
- In Custom JavaScript, delete the snippet that contains both
gk.datatables.optionsandexportOptions. - Click Update, then export the file again.
If the View’s Custom JavaScript field has no such code, look for it in your theme’s files or in a code snippets plugin.