xlsx

How to create a .csv file with semicolon separation in XLSX npm


I'm triying to create a csv file with XLSX package from npm, and the result is the values separated by , (colon) and i want to be by ; (semicolon). How can I do it?

LSX.utils.book_append_sheet(workbook, worksheet, fileName);
const options = { cellDates: true };
const file = XLSX.writeFile(workbook, `${fileNameWithLocation}${extension}`, options);

Solution

  • Documentation Link: https://docs.sheetjs.com/docs/api/utilities/csv/

    Should be something like this

    const XLSX = require("xlsx");
    const fs = require("fs");
    
    const data = [
      ["Name", "Age", "Country"],
      ["Alice", 30, "Canada"],
      ["Bob", 25, "USA"],
      ["Charles, Jr.", 35, "UK"],
    ];
    
    const worksheet = XLSX.utils.aoa_to_sheet(data);
    let csv = XLSX.utils.sheet_to_csv(worksheet, { FS: ";" });
    
    fs.writeFileSync("output.csv", csv);