Tables in JavaScript Excel
23 Sep 20263 minutes to read
Create workbook tables with sheet.tables.add(name, range, headerRowCount?).
Create a table
import { Workbook } from '@syncfusion/ej2-xlsx';
const workbook: Workbook = Workbook.create();
const sheet = workbook.sheet(0);
sheet.cell('A1').value = 'Product';
sheet.cell('B1').value = 'Qty';
sheet.cell('A2').value = 'Laptop';
sheet.cell('B2').number = 5;
sheet.cell('A3').value = 'Phone';
sheet.cell('B3').number = 12;
const table = sheet.tables.add('SalesTable', 'A1:B3', 1);
// Optional named style and totals row
table.style = { name: 'TableStyleMedium9' };
table.totalsRowEnabled = true;
table.totalsRowShown = true;import { Workbook } from '@syncfusion/ej2-xlsx';
const workbook = Workbook.create();
const sheet = workbook.sheet(0);
sheet.cell('A1').value = 'Product';
sheet.cell('B1').value = 'Qty';
sheet.cell('A2').value = 'Laptop';
sheet.cell('B2').number = 5;
sheet.cell('A3').value = 'Phone';
sheet.cell('B3').number = 12;
const table = sheet.tables.add('SalesTable', 'A1:B3', 1);
table.style = { name: 'TableStyleMedium9' };
table.totalsRowEnabled = true;
table.totalsRowShown = true;style is a TableStyle object (name plus optional banding flags). Authored tables are ordinary worksheet tables.
Access and remove tables
import { Workbook } from '@syncfusion/ej2-xlsx';
const workbook: Workbook = Workbook.create();
const sheet = workbook.sheet(0);
const table = sheet.tables.add('SalesTable', 'A1:B3', 1);
const count = sheet.tables.count;
const all = sheet.tables.list();
const first = sheet.tables.get(0);
const exists = sheet.tables.has('SalesTable');
sheet.tables.remove(table);
// sheet.tables.removeAt(0);
// sheet.tables.clear();import { Workbook } from '@syncfusion/ej2-xlsx';
const workbook = Workbook.create();
const sheet = workbook.sheet(0);
const table = sheet.tables.add('SalesTable', 'A1:B3', 1);
const count = sheet.tables.count;
const all = sheet.tables.list();
const first = sheet.tables.get(0);
const exists = sheet.tables.has('SalesTable');
sheet.tables.remove(table);