node. JS operations Excel tables and XML files common NPM

Source: Internet
Author: User

In the daily work will often use to convert some Excel form files into Json,xml,js and other formats, the following is the NPM I used in everyday.

1, Node-xlsx:

NODE-XLSX can convert Excel files to the above mentioned several file formats, the common way to see GitHub source code and examples: node-xlsx

Referencing directly in the action file

var xlsx = require ("node-xlsx");

Read Excel

var list = Xlsx.parse ("./excel/" + excelname);

The read-out is an array that contains each sheet

[

{name: ' Sheet1 ', Data: [[Object], [object], [object], [object], [object]},
{name: ' Sheet2 ', data: [[Object]]}

]

Name=sheet Name

Data= the data for each sheet,

The rest of the operation is flexible ...

2, Xlsx-to-json, from the name can know what he is with the hair, but also to parse the Excel table into JSON format files, you can also find them on GitHub, to give a very simple example:

var xlsxj = require (' Xlsx-to-json '); Xlsxj ({    "./china/sample.xlsx",    " Output.json "function(err, result) {    if(err) {        Console.error (err );    } Else {        Console.log (result);    }});

You will see a Output.json file in the root directory, this file is the content of the Sample.xlsx file parsing above.

3, Xml2js, as the name implies is used to parse the XML file, also can be found on GitHub above, to see a small demo it:

var parsestring = require (' Xml2js '). parsestring; // var xml = "<root>hello xml2js!</root>"; var xml = ' <?xml version= ' 1.0 ' encoding= ' UTF-8 '?> ' +    ' <root> ' +    ' <child foo= ' bar ' > ' +    ' <grandchild baz= "Fizbuzz" >grandchild content</grandchild> ' +    ' </child> ' +    ' < Sibling>with content 1</sibling> ' +    ' <sibling>with content 2</sibling> ' +    ' </root > 'function  (err, result) {    console.dir (result);});

Output an object:

{root:    {child: [[Object]],     ' with content 1 ', ' with content 2 '    }}}

node. JS operations Excel tables and XML files common NPM

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.