0

From the example from js-xlsx, we know that after reading a file, we can add new data into that particular sheet:

var XLSX = require('xlsx');
var wb = XLSX.readFile('sheetjs.xlsx');
add_cell_to_sheet(wb.Sheets.SheetJS, "F6", 12345);
XLSX.writeFile('sheetjs-new.xlsx', wb);

But how to do if my data is not just a single cell? I have a json data that I would like to add into the file that I read. How to add the json data?

Coolguy
  • 2,225
  • 12
  • 54
  • 81

1 Answers1

0

After you readFile, you want to create worksheet by json_to_sheet property.

var ws = XLSX.utils.json_to_sheet(jsonPrep);

Then you want to add it to the sheet you want.

workbook.Sheets.SheetJS = ws;

Then you want to write the file.

XLSX.writeFile(workbook, 'sheetjs.xlsx');
Dan Tran
  • 1
  • 1