rikkertkoppes / json2xls

canonically transform json to an excel document
278 stars 85 forks source link

YOu dont need this lib anymore #59

Open wandersonsousa opened 10 months ago

wandersonsousa commented 10 months ago

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.");
}
CmD0 commented 4 months ago

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.