0

Is it possible to dynamically add columns to an excel table using exceljs?

I wrote this code:

        let workBook = new excel.Workbook();
        let workSheet = workBook.addWorksheet('report');

        workSheet.getRow(1).values = columns;

which creates columns with the names in the columns list. But I don't know how to add key's to items in this list.

In normal/static usage I create something like this:

        workSheet.columns = [
            {key: 'id', name: 'id'},
            {key: 'firstName', 'firstName'},
            {key: 'lastName', name: 'lastName'}
        ]

to map object from db to these key's.

And the problem is, I don't know how to make a pair of key-values(name) where my key and values would be the same as the object in my list - columns.

Does anybody have an idea/solution? Thanks for any help :)

rromashka
  • 3
  • 2
  • Please have a look at this [question here](https://stackoverflow.com/questions/52970298/creating-dynamic-number-of-columns-or-header-in-excel-in-nodejs-javascript). Hope it will be helpful. – AhmerMH Jul 29 '20 at 08:00
  • @AhmerMH no, i see it –  Jul 29 '20 at 08:02

0 Answers0