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