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.

CSVExcel (XLSX)PDFClipboardFilter-aware

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

AttributeRequiredDescription
exportOptionalShow the export controls (format menu + Copy to Clipboard). Accepts true or false. Defaults to false.
sourceRequiredThe data source URL (JSON, CSV, or Google Sheet). The exported file is built from this data, after filters and search are applied.
includeOptionalComma-separated list of columns to show. Hidden columns are not exported.
excludeOptionalComma-separated list of columns to hide. Excluded columns are not exported.
searchOptionalEnable the live search bar. Active search terms narrow what is exported.
filtersOptionalEnable 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

FormatExtension / MIMEHow it is produced
CSV.csv · text/csvThe 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.sheetA genuine OOXML workbook assembled server-side with ZipArchive, containing the proper package parts and one worksheet named "TableCrafter Export".
PDF.pdf · application/pdfA 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":

⚠️

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:

  1. The browser POSTs to admin-ajax.php with action=tc_export_data, the chosen format, the row data, the columns, a filename, and a nonce.
  2. The handler verifies the tc_export_nonce and confirms the user has the read capability, then generates the file into a protected uploads folder (wp-uploads/tablecrafter-exports/, locked down with .htaccess and an index.php).
  3. The response includes a one-time download_url (a tc_download_export request guarded by its own tc_download_nonce). The browser follows it to download the file.
  4. 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:

// 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

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.