xlsx-template icon indicating copy to clipboard operation
xlsx-template copied to clipboard

Append more values to sharedStrings of workbook

Open NayOoLwin5 opened this issue 3 years ago • 7 comments

My workbook is already loaded with values and placeholders. The total of sharedStrings is now 530. I would like to add(append) more values to the sharedStrings along with a loop.

NayOoLwin5 avatar Jun 29 '22 04:06 NayOoLwin5

This is library for report generation, why do you want to put values into sharedStrings using it?

kant2002 avatar Jun 29 '22 07:06 kant2002

Hi @kant2002, I am also using it for report generation. In my case, I am delaying the values parsed into template.substitute() by a second using mqtt. The values are 100 rows each second and the total is 1500. It does not work as expected. The workbook remains same with first 100 rows. Is there anyway like appending values to the workbook?

NayOoLwin5 avatar Jun 29 '22 08:06 NayOoLwin5

Aah, now it make sense, so you essentially want stream substitution process. And be able append more substitution values over and over again until you done. Is this correct?

Example

var batch1 = [
    {name: "John Smith", age: 20},
    {name: "Bob Johnson", age: 22}
];

// Perform substitution
template.substitute(sheetNumber, values);

var batch2 = [
    {name: "Andrii Hopak", age: 33},
    {name: "Marat Beysabekov", age: 52}
];

// Feed additional data to substitution process
template.continueSubstitute(sheetNumber, values);

kant2002 avatar Jun 29 '22 08:06 kant2002

It is throwing this error -

debug: TypeError: template.continueSubstitute is not a function

NayOoLwin5 avatar Jun 29 '22 09:06 NayOoLwin5

There no such functionality in the library at the moment. You have to collect all data into one object, and if you are done, then perform substitution.

kant2002 avatar Jun 29 '22 09:06 kant2002

Understood @kant2002. In addition, does this library support merging multiple excel files into one? If it does, it solves my issue.

NayOoLwin5 avatar Jun 30 '22 03:06 NayOoLwin5

No, merging of XLSX files should happens via other means. This library is for simple template substitution.

kant2002 avatar Jun 30 '22 03:06 kant2002