I want to export xlsx files using js-xlsx on my Node.JS server. I can read files and save them. But as i try to fill the Table with content it does not work.
I fill it using lines like these:
for (var i = 0; i < workbook.SheetNames.length; i++) {
var sheet = workbook.Sheets[workbook.SheetNames[i]];
var studenten = stapel[workbook.SheetNames[i]];
sheet["A1"] = {v: "This is a test!",t:"s"};
workbook.Sheets[workbook.SheetNames[i]] = sheet;
}
, I tried using this notation for the cell address too
{c:0,r:0}
but as i export my file the tables are empty. Creating different worksheets works fine but i can't fill the tables with content. Could someone here enlighten me on how to correctly address the tables and manipulate their content?
Thanks in advance!
update: even
function Workbook() {
if (!(this instanceof Workbook)) return new Workbook();
this.SheetNames = [];
this.Sheets = {};
}
var workbook = new Workbook();
workbook.SheetNames.push("1");
workbook.Sheets[1] = {'A1': {v: "HI",t:"s"}};
doesn't work. I think I don't understand the API!
I stumbled upon this today myself and took some time to find the reason. The solution is to set the "!ref" Value in a worksheet:
workbook.Sheets[1] = {'!ref': "A1", 'A1': {v: "HI",t:"s"}};
The "!ref" is used to define the area that contains data within the sheet. This is from the official documentation:
sheet['!ref']: A-1 based range representing the sheet range. Functions that work with sheets should use this parameter to determine the range. Cells that are assigned outside of the range are not processed. In particular, when writing a sheet by hand, cells outside of the range are not included