I'm trying to format some data into a Excel table, I already have the data written in the Excel file, but I want it as a table, is there any way to do this, if not, is there any way with another npm package
I'm trying to format some data into a Excel table, I already have the data written in the Excel file, but I want it as a table, is there any way to do this, if not, is there any way with another npm package
Share Improve this question asked Feb 19, 2020 at 21:17 William DamWilliam Dam 1292 silver badges12 bronze badges2 Answers
Reset to default 3You could convert the range to table:
const sheet = context.workbook.worksheets.getItem("Sample");
let expensesTable = sheet.tables.add("A1:E7", true);
expensesTable.name = "ExpensesTable";
here is the sample gist that you could have a try https://gist.github./lumine2008/8eccb88f7fccf34b63c7ecd5fd05aaea
Source: Tables allow for in-sheet manipulation of tabular data.
import * as exceljs from 'exceljs';
const workbook = new exceljs.Workbook();
const worksheet = workbook.addWorksheet('William');
// add a table to a sheet
worksheet.addTable({
name: 'Dam',
ref: 'A1',
headerRow: true,
totalsRow: true,
style: {
theme: 'TableStyleDark3',
showRowStripes: true,
},
columns: [
{name: 'Date', totalsRowLabel: 'Totals:', filterButton: true},
{name: 'Amount', totalsRowFunction: 'sum', filterButton: false},
],
rows: [
[new Date('2019-07-20'), 70.10],
[new Date('2019-07-21'), 70.60],
[new Date('2019-07-22'), 70.10],
],
});