The xlsx format is the format used by office2007 and is an XML-based compressed file format.
1. Installation:npm install node-xlsx
2. Convert xlsx to JSON file
1) Prepare an xlsx file: information.xlsx, with two tables, user and manage, respectively
2) Code:
var xlsx = require ("node-xlsx"); var fs = require ("FS"); // xlsx to JSON var xobj = Xlsx.parse ("xlsx/informations.xlsx"); Fs.writefilesync ("Json/informations.json", Json.stringify (xobj));
3) After running, a Informations.json file is generated and placed in the JSON folder, the resulting JSON format is:
3. JSON converted to xlsx file:
1) Prepare a JSON file: Info.json:
[ { "name": "Table Name 1", "Data" : [ ["Element 101", "element 102"], [" Element 111 "," element "," [element 121 "," element 122 "] }, { " name ":" Table Name 2 ", "Data" : [ ["element 201", "Element 202"], ["element 211", "element 212"], [" Element 221 "," element 222 "] }]
2) Code:
var xlsx = require ("node-xlsx"); var fs = require ("FS"); // JSON to xlsx var jobj = Fs.readfilesync (__dirname + "Json/info.json", "UTF8"),//encode file = Xlsx.build (Json.parse (jobj)); Fs.writefilesync ("xlsx/info.xlsx", file);
3) info.xlsx files generated after the run:
4. Portal:
Npm:https://www.npmjs.com/package/node-xlsx
Github:https://github.com/mgcrea/node-xlsx
[Device Forget] node-xlsx