Data Export (CSV, Excel, PDF)
TableCrafter lets visitors download the table they are looking at as a real CSV, Excel (XLSX), or PDF file, or copy it straight to the clipboard. Exports run through a single server-side handler that produces genuine, openable files and respects whatever filters, search, and sorting are currently applied.
Overview
When export is enabled, TableCrafter renders a set of export controls above the table: a format menu (CSV / Excel / PDF) and a Copy to Clipboard button. CSV from the simple button is built right in the browser, while Excel and PDF are generated on the server through the tc_export_data AJAX action and then streamed back as a downloadable file.
As of version 3.5.6, all three formats are honest files. The Excel export is a genuine OOXML .xlsx workbook assembled with PHP's ZipArchive (a real, openable spreadsheet), and the PDF export is a structurally valid PDF 1.4 document with a correct object table and cross-reference table. Neither is HTML or CSV renamed with a different extension.
Exports reflect the current view. Whatever the user has filtered, searched, or sorted is what ends up in the file, because TableCrafter exports the filtered dataset rather than the raw source.
Enabling export
With the shortcode
Add the export attribute to the [tablecrafter] shortcode. It is off by default, so set it to true to show the export controls.
# Enable the export menu and clipboard button
[tablecrafter source="https://api.example.com/products.json" export="true"]
Export pairs naturally with search and filters so users can narrow the data first, then export exactly what they see:
[tablecrafter source="https://api.example.com/products.json"
search="true" filters="true" export="true" per_page="25"]
With the Visual Shortcode Builder
Open the TableCrafter admin menu, enter your data source, and toggle Export in the options panel. The builder writes export="true" into the generated shortcode and updates the live preview so you can confirm the controls appear before copying the shortcode.
With the Gutenberg block or Elementor widget
Both editors expose an Export toggle in their settings. The block describes it as adding CSV download and copy-to-clipboard buttons that respect current filters and search; turning it on is equivalent to export="true".
Shortcode attribute reference
| Attribute | Required | Description |
|---|---|---|
| export | Optional | Show the export controls (format menu + Copy to Clipboard). Accepts true or false. Defaults to false. |
| source | Required | The data source URL (JSON, CSV, or Google Sheet). The exported file is built from this data, after filters and search are applied. |
| include | Optional | Comma-separated list of columns to show. Hidden columns are not exported. |
| exclude | Optional | Comma-separated list of columns to hide. Excluded columns are not exported. |
| search | Optional | Enable the live search bar. Active search terms narrow what is exported. |
| filters | Optional | Enable column filters. Active filters narrow what is exported. |
There is no separate attribute to pick which formats appear. When export="true", the format menu offers CSV, Excel, and PDF, and the Copy to Clipboard button is always shown alongside it.
Export formats
| Format | Extension / MIME | How it is produced |
|---|---|---|
| CSV | .csv · text/csv | The simple CSV button builds the file in the browser as a Blob download. The server-side CSV path writes a UTF-8 BOM (for clean Excel opening) and uses RFC 4180 quoting. |
| Excel | .xlsx · application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | A genuine OOXML workbook assembled server-side with ZipArchive, containing the proper package parts and one worksheet named "TableCrafter Export". |
.pdf · application/pdf | A valid PDF 1.4 document generated server-side, rendering the table as text in Helvetica with byte-accurate cross-reference offsets. |
The frontend labels the Excel option excel, but the canonical format key is xlsx; the handler accepts excel as an alias and routes it to the same XLSX writer. Both produce the identical real workbook.
Copy to clipboard
The Copy to Clipboard button copies the current (filtered) rows as tab-separated values, with the column labels as the first line. Tab separation means you can paste directly into Excel, Google Sheets, or Numbers and have it land in proper cells. The button briefly flips to "Copied!" to confirm.
It uses the modern navigator.clipboard API where available and falls back to a hidden textarea with document.execCommand('copy') on older or non-secure-context browsers, so it works without a file download.
What gets exported (filters and columns)
Export is intentionally "what you see is what you get":
- Filters and search: By default TableCrafter exports the filtered dataset, so any active column filters or search terms are applied to the export.
- Columns: Columns hidden via
include/exclude, or any column marked non-exportable, are omitted from the file. Header labels in the export use the column's display label when one is available. - Cell formatting: Values are cleaned for export. HTML is stripped to plain text, date-like values are formatted per the active template's date format, and numeric values are normalised, so the file stays tidy in spreadsheet tools.
If the current filter/search combination yields no rows, there is nothing to export. The CSV/Excel/PDF buttons will report that there is no data rather than producing an empty file.
How the server-side export works
For Excel and PDF (and the server CSV path), the table sends its already-rendered rows and column configuration to WordPress:
- The browser POSTs to
admin-ajax.phpwithaction=tc_export_data, the chosenformat, the rowdata, thecolumns, afilename, and a nonce. - The handler verifies the
tc_export_nonceand confirms the user has thereadcapability, then generates the file into a protected uploads folder (wp-uploads/tablecrafter-exports/, locked down with.htaccessand anindex.php). - The response includes a one-time
download_url(atc_download_exportrequest guarded by its owntc_download_nonce). The browser follows it to download the file. - After the download is served, the temporary file is removed and its transient deleted. Any stragglers are swept by a cleanup routine that deletes export files older than an hour.
Download links are short-lived: the generated file is stored behind a transient that expires after 5 minutes, and the file is deleted as soon as it is downloaded.
Developer notes
The export pipeline lives in includes/class-tc-export-handler.php (class TC_Export_Handler). A few extension points worth knowing:
- Export templates filter:
tc_export_templateslets you add or modify named templates. Each template controls whether a metadata footer is included and which date and number formats are applied. Built-in templates aredefault,business, anddata_analysis. - Metadata footer: When a template enables it (or the request asks for it), exports can append an "Export Information" block listing the generation timestamp, total record count, and any applied filters or sort order.
- Capability: The AJAX handler requires the
readcapability, so the feature is available to logged-in subscribers and above; it is also registered for non-logged-in visitors via thenoprivhook.
// Add a custom export template via the tc_export_templates filter
add_filter( 'tc_export_templates', function ( $templates ) {
$templates['invoice'] = [
'name' => 'Invoice',
'description' => 'Currency-formatted report',
'include_metadata' => true,
'date_format' => 'M j, Y',
'number_format' => '$0.00',
];
return $templates;
} );
Troubleshooting
- Excel export errors: XLSX generation requires PHP's ZipArchive extension. If it is missing, the handler reports that ZipArchive is required; enable the
zipPHP extension on the server. - No export buttons appear: Confirm
export="true"is set (it defaults to off) and that the table actually loaded data. - Download link expired: Generated files are only retrievable for a few minutes. Re-run the export to get a fresh link.
Next, see filtering-and-search.html to control exactly which rows make it into an export, and column-management.html for choosing which columns are included.