json2xls
json2xls copied to clipboard
YOu dont need this lib anymore
Just use the npm package xlsx, and:
import xlsx from "xlsx";
export function saveJsonToSheet(data, path) {
console.log("building xlsx for data", data);
const workbook = xlsx.utils.book_new();
const worksheet = xlsx.utils.json_to_sheet(data);
xlsx.utils.book_append_sheet(workbook, worksheet, "Sheet1");
// Write xlsx data to a file (e.g., output.xlsx)
xlsx.writeFile(workbook, path);
console.log("xlsx file created successfully.");
}
This.
xlsx (the npm package for SheetsJS) is the main dependency for most newer json to xls libraries, just learn and use the xlsx workflow and you'll be good to do any and all operations you need to build and work with excel files in javascript/typescript
EDIT: json2xls broke recently due to a deep dependency releasing a breaking change, another reason to move to this way of doing things.