var fs = require("fs"); var xlsx = require('node-xlsx'); const path = require('path') var compressing = require("compressing"); /** * 读取excel数据 * @param {*} url_excel excel路径 * @param {*} sheetnum 是否多个sheet * @returns */ function getExcelData(url_excel, sheetnum = 1) { var sheets = xlsx.parse(url_excel); return sheetnum == 1 ? sheets[0].data : sheets; } /** * 生成json * @param {*} data json数据 * @param {*} url_json 生成json路劲 */ function createJson(data, url_json) { console.log(url_json,data); fs.writeFile(url_json, JSON.stringify(data, "", "\t"), "utf8", function (err) { if (err) throw err; console.log(" WriteFile: " + url_json + " OK!"); }); } /** * * @param {*} jsonpath * @param {*} zippath */ function createZip(jsonpath, zippath) { compressing.zip.compressDir(jsonpath, zippath) .then(() => { console.log('success'); }) .catch(err => { console.error(err); }); // compressing.zip.compressDir('data', 'nodejs-compressing-demo.zip'); } module.exports = { getExcelData, createJson, createZip, }