最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Make a data table using exceljs - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

You 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],
  ],
});
发布评论

评论列表(0)

  1. 暂无评论