Guides

Export an Airtable view to CSV with a script (code included)

If you're comfortable with a little JavaScript, Airtable's scripting can turn a view into CSV text in about 30 lines. Below is a snippet that keeps the view's filters and sort order, writes the columns you choose, and escapes values properly.

The script

Paste this into a Scripting extension (or an automation's Run script action) and change the table and view names.

const table = base.getTable('Orders');
const view = table.getView('Export - do not edit');
// List the columns you want, in order. Scripting can't read which fields a view hides.
const fields = ['Order ID', 'Customer', 'Status', 'Total'].map((n) => table.getField(n));
const query = await view.selectRecordsAsync({ fields });

function cell(v) {
  let s = v == null ? '' : String(v);
  if (/^[=+\-@\t\r]/.test(s) && isNaN(Number(s))) s = "'" + s; // formula-injection guard
  return /[",\r\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
}

const rows = [fields.map((f) => cell(f.name)).join(',')];
for (const r of query.records) {
  rows.push(fields.map((f) => cell(r.getCellValueAsString(f))).join(','));
}
const csv = '\uFEFF' + rows.join('\r\n'); // BOM so Excel reads UTF-8
output.text(`${query.records.length} records, ${csv.length} characters`);

What each part does

Running it on a schedule

In the Scripting extension the script only runs when someone clicks Run. For a schedule, put it in an automation with an At a scheduled time trigger. The catch: an automation can't attach the resulting text as a file to its own Send email action. You'd post the CSV to an external email API (SendGrid, Mailgun, Postmark) from the script, which means an extra account and an API key sitting in your base. Automation scripts also have time and memory limits, so very large views may need batching.

When to skip the script

If the goal is "this view, as a CSV, in these inboxes, every Monday at 8", a dedicated tool saves you the email API, the key management and the failure handling. ViewCourier runs the export from a read-only token, sends the CSV as an attachment and emails you if a run fails. For a one-off export of every table, the free Airtable base to CSV tool runs in your browser.

Let ViewCourier do it

Connect a read-only Airtable token, pick a view, and choose daily, weekly or monthly at your time and timezone. Every run emails a clean CSV attachment to up to five people. The free trial lasts 14 days and needs no credit card.

Start free trial

More guides