xlsx - json 互转


个人博客:柚子青年。

原文链接:xlsx - json 互转

xlsx 转 json

const fs = require('fs');
const xlsx2json = require('xlsx2json');
xlsx2json(
    './文档.xlsx', // url
    {
        dataStartingRow: 3,  // 第几行开始
        mapping: {    // 解析 key value
            'key1': 'A',
            'key2': 'B',
        }
    }
).then(jsonArray => {  // 输出数组  格式自行log
    fs.writeFileSync('./文档.json', JSON.stringify(jsonArray));
});

json 转 xlsx

const fs = require('fs');
const json2xls = require('json2xls');
const json = require("./json");
let jsonArr = [];
for (let jsonKey in json) {
    jsonArr.push({
        "A": json[jsonKey].cn, // A 内容
        "B": json[jsonKey].en, // B 内容
    });
}
fs.writeFileSync('./data.xlsx', json2xls(jsonArr), 'binary');

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM