has been doing an online selection of the system, selected the current more popular node.js. Today, I am thinking about how to introduce students or teachers to the information, involving a little bit more, I have a part of the Excel table at hand. You want to turn Excel into JSON and pour it into the mongodb.
Search the information on the Internet, there are a lot. Most of them are C # or Python, do you want to compile your own, you can not run all kinds of missing libraries. Google found out that there was this module in node. The URL is Https://www.npmjs.com/package/xls-to-json.
The steps are probably recorded:
To any location, create a new Package.json. I don't know why I tried the direct NPM installation, so that's it.
{
"name": "abc",
"version": "0.0.0",
"private": True,
"scripts": {
"start": "Node./bin/www"
},
"dependencies": {
"Xls-to-json": "*"
}
}
After saving direct NPM install installation package. Then create a new app.js
NODE_XJ = require ("Xls-to-json");
NODE_XJ ({
input: "Test.xls",//input xls
output: "Output.json"//Output JSON
//sheet: "Sheet1",//specific SheetName
}, function (err, result) {
if err) {
console.error (err);
} else {
console.log (result);
}
});
This is the code for the top web site that is pasted directly. Then the runtime sheet the error, and I'll comment directly.
Put the Test.xls in the same directory, and then node app.js on the line ...
Is the information of the classmate, hit the code. Can be seen as a success anyway.
This method is very simple, rough. Here mark and share, there are better ways to pass by, or advice to comment on the message. Thank you.
The above mentioned is the entire content of this article, I hope you can enjoy.