javascript - 将javascript对象写入xlsx,键为字符串,值为数组
问题描述
下面是要写入 excel.xlsx 文件的 Javascript 对象
{
"emp1":['M','A','N','X','Y', 'Z'....],
'emp2':['car','bike'],
'emp3':['laptop','mouse']
}
以下是excel中的输出格式:-
员工 | 1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|---|
emp1 | 米 | 一个 | ñ | X | 是的 | Z |
emp2 | 车 | 自行车 | ||||
emp3 | 笔记本电脑 | 鼠 |
下面是我试图将输出转换为 excel 的代码
const writeIntoExcel = (shiftAssigned) => {
console.log("shift Assigned", shiftAssigned);
let content = JSON.parse(shiftAssigned);
// let content = shiftAssigned;
let newWb = xlsx.utils.book_new();
let newWs = xlsx.utils.json_to_sheet(content);
let sheetName = (config.month + '_' + config.year);
let fileName = (config.month + '_' + config.year + '.xlsx');
// config.log("filename", fileName, sheetName);
xlsx.utils.book_append_sheet(newWb, newWs, sheetName);
xlsx.writeFile(newWb, fileName);
}
writeIntoExcel(shiftAssigned);
提前感谢您的帮助
解决方案
推荐阅读
- javascript - 无法在量角器 e2e 测试中找到 MatSnackBar 元素
- python - 子进程不会捕获 powershell 输出
- docker - LC_ALL:无法更改语言环境 (en_US.UTF-8) newaliases:在 sSMTP 中,别名是从纯文本文件中读取的
- cmder - 如果文件夹的名称中有空格并且我不能/不想更改它的名称,如何键入文件的路径?
- php - Firebase - PHP - 错误解码消息:无法处理消息上的未知字段collection_Id
- python - 如何在烧瓶 sqlalchemy 中保存图像列表
- c++ - 函数将 const ref 返回到 std::unique_ptr,它可以返回 null 吗?
- esp32 - Heltec ESP32 LoRa 接收中断
- python - 如何在从源代码编译的 Python 上安装 DistUtilsExtra?
- python - AttributeError:“str”对象没有属性“get_lect”