I created an Excel file template with just a row with columns on it.
worksheet.columns = [
{ header: 'Id', key: 'id', width: 10 },
{ header: 'Name', key: 'name', width: 32 },
{ header: 'D.O.B.', key: 'dob', width: 10}
];
and later I have to load the same Excel file in different transactions and when I try to retrieve the column key I get unidentified. I want column keys because I want to add rows with key-value
const rows = [
{id:1, name: 'Barbara', dob: new Date()},
{id:2, name: 'Barbara 2', dob: new Date()}
];
const newRows = worksheet.addRows(rows);
isn't this possible? I can use another approach row by array but for this, I need to map the data and find the proper column. I guess it's not possible to get column keys while I load the Excel template file.
// Add column headers and define column keys and widths
// Note: these column structures are a workbook-building convenience only,
// apart from the column width, they will not be fully persisted.
Found this in the documentation.
Excel Style and data copy now working well. So this workaround to read header data only from the template and style set programmatically.
This code will work
Saved
template.xlsxdemo code.
Save as
demo.jsInstall Dependency
Run it
Result
Open `result.xlsx' file.