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