1. Data Grid docs
  2. Rows and records

Export

Save the matching or selected records, in the visible columns and their order, as CSV, a typed XLSX workbook or PDF, flat or with the view's layout.

Export saves what the user is looking at: the records that match the search and filters, in the current sort order, with the visible columns in their order and under their headings as renamed in the view. It is the "send me that list" button, as a CSV file, an Excel workbook with real numbers and dates, or a PDF.

Open the report example and export it with its layout · the selection example: export the selected rows

In the grid

Export in the header asks for the format and, while records are selected, whether to export All matching records or Selected records, then downloads the file. For XLSX and PDF, Keep the layout: groups, totals, widths and formatting exports the view's shape as well as its records; see Keep the layout. Where the device supports it, Share hands the file to the system's share sheet.

FormatWhat it holds
CSVThe display text of each cell, UTF-8
XLSXOne new sheet, "Results", with numbers, dates and the columns' number formats; no formulas, connections or links to the source
PDFThe same table, laid out for printing

From code

exportResults(format, { selected, layout }) returns the file as a Blob, to upload or attach. download(format, { selected, fileName, layout }) saves it through the browser; the file name defaults to the title and the record count. With a sharing service, createShareLink() publishes the matching records as an XLSX copy and resolves with { id, url }, and revokeShareLink() takes the last link back. openDialog('export') opens the grid's own dialog.

JavaScript

import { mountTable } from '@8sheets/data-grid';

const grid = await mountTable(document.querySelector('#orders'), { title: 'Orders', data: orders, rowSelection: 'multiple' });

document.querySelector('#excel').onclick = () => grid.download('xlsx', { fileName: 'orders.xlsx' });
document.querySelector('#selected').onclick = () => grid.download('csv', { selected: true, fileName: 'selected-orders.csv' });
// The grouped view with its totals row, widths and colour scales, as Excel shows it.
document.querySelector('#report').onclick = () => grid.download('xlsx', { layout: true, fileName: 'orders-report.xlsx' });

// Attach the current view to an e-mail on your server.
document.querySelector('#send').onclick = async () => {
  const pdf = await grid.exportResults('pdf');
  await fetch('/api/mail/report', { method: 'POST', body: pdf });
};

React

import { useRef } from 'react';
import { DataGrid } from '@8sheets/data-grid-react';

export function Orders({ options }) {
  const ref = useRef(null);
  return (
    <>
      <button onClick={() => ref.current.download('xlsx', { fileName: 'orders.xlsx' })}>Excel</button>
      <button onClick={() => ref.current.download('pdf', { selected: true })}>Selected as PDF</button>
      <div style={{ height: 480 }}><DataGrid ref={ref} options={{ ...options, rowSelection: 'multiple' }} /></div>
    </>
  );
}

Vue

<script setup>
import { computed, ref } from 'vue';
import { DataGrid } from '@8sheets/data-grid-vue';

const props = defineProps({ orders: Array });
const options = computed(() => ({ title: 'Orders', data: props.orders, rowSelection: 'multiple' }));
const dataGrid = ref(null);
</script>

<template>
  <button @click="dataGrid.download('xlsx', { fileName: 'orders.xlsx' })">Excel</button>
  <button @click="dataGrid.download('csv', { selected: true })">Selected as CSV</button>
  <div style="height: 480px"><DataGrid ref="dataGrid" :options="options" /></div>
</template>

Angular

import { Component, Input, ViewChild } from '@angular/core';
import { DataGridComponent, DataGridOptions } from '@8sheets/data-grid-angular';

@Component({
  selector: 'app-orders',
  imports: [DataGridComponent],
  template: `
    <button (click)="grid.download('xlsx', { fileName: 'orders.xlsx' })">Excel</button>
    <button (click)="grid.download('csv', { selected: true })">Selected as CSV</button>
    <eight-data-grid #grid [options]="options" style="height: 480px" />`,
})
export class Orders {
  @Input() options: DataGridOptions = {};
  @ViewChild('grid') grid!: DataGridComponent;
}

Keep the layout

A flat export holds the records. With layout: true (or the dialog's checkbox), XLSX and PDF also keep how the view looks:

  • header bands as merged cells over their columns;
  • group rows with their summaries, as outline levels: every group is open in the file, and Excel can collapse them with its outline buttons;
  • the levels of a tree, as outline levels too;
  • the totals row;
  • column widths and the frozen heading rows;
  • number formats and the conditional formatting rules: data bars, colour scales and value rules become Excel's own conditional formats, so they keep working when the numbers change in Excel.

CSV stays flat with or without layout. The layout export needs local records: a server source's exportResults gets the same request as before, and the dialog doesn't offer the checkbox.

The export goes to the source's exportResults (exportUrl in remoteTableSource), which gets the same view state without a row limit and returns the file. formats lists the formats your server writes; remoteTableSource offers ['xlsx', 'csv'] by default. A source without exportResults has no Export button.

Limits

  • XLSX and PDF hold at most 1,048,575 records and 16,384 columns, Excel's sheet limits. CSV has no limit.
  • Without layout, exports are flat: they hold the records, not group rows, the totals row or conditional formatting. With it, XLSX and PDF keep those, for local records only.
  • Exports never hold what a renderer or a sparkline drew, nor detail panels.
  • A large PDF takes as many pages as it needs; for long lists, CSV or XLSX is the better choice.