如何在 XLSX npm 中创建以分号分隔的 .csv 文件

问题描述 投票:0回答:1

我正在尝试使用 npm 中的 XLSX 包创建一个 csv 文件,结果是用 , (冒号)分隔的值,我想用 ; (分号)。我该怎么办?

LSX.utils.book_append_sheet(workbook, worksheet, fileName);
const options = { cellDates: true };
const file = XLSX.writeFile(workbook, `${fileNameWithLocation}${extension}`, options);
xlsx xlsxwriter
1个回答
0
投票

文档链接:https://docs.sheetjs.com/docs/api/utilities/csv/

应该是这样的

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);
© www.soinside.com 2019 - 2024. All rights reserved.