[Device Forget] node-xlsx

Source: Internet
Author: User
Tags install node npm install node

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.