| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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,
- }
|