根目錄data文件下inputer文件夾下test.xlsx,輸出文件test.json到outer文件夾下爲test.json文件,process.cwd()得到根目錄 、轉爲 .json .text .doc均可以;node
方法1: node-xlsx、fsjson
var xlsx = require("node-xlsx"); var fs = require('fs'); var path = require('path'); var list = xlsx.parse(process.cwd() + '/data/inputer/test.xlsx'); writeFile(path.join(process.cwd()+'/data/outer',"test.json"),JSON.stringify(list)); function writeFile(fileName,data) { fs.writeFile(fileName,data,'utf-8',complete); function complete(err){ if(!err){ console.log("文件生成成功"); } } }
方法2: xls-to-jsonui
var node_xj = require("xls-to-json"); node_xj({ input: process.cwd()+"/data/inputer/test.xlsx", output: process.cwd()+"/data/outer/test.json" }, function (err, result) { if (err) { console.error(err); } else { console.log(result); } });