Home > Article > Web Front-end > Node.js implements Excel conversion to JSON_node.js
I have been working on a system for online course selection, using the popular node.js. Today I was thinking about how to import student or teacher information, which involves a relatively large amount, and I happen to have some excel tables on hand. I just want to convert excel to json and then pour it into mongodb.
I searched the Internet and found a lot of information. Most of them are in C# or python. You have to compile them yourself, or you can't run them due to various missing libraries. I googled and found that this module actually exists in node. The URL is https://www.npmjs.com/package/xls-to-json. .
Maybe record the steps:
Go to any location and create a new package.json. I don't know why I tried to install it directly with npm but it didn't work, so I just left it like that.
{ "name": "abc", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "xls-to-json": "*" } }
After saving, directly npm install the 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 of the above website pasted directly. Then there was an error in the sheet when running, so I commented directly.
Put test.xls into the same directory, and then node app.js. .
It’s all classmates’ information, so it’s coded. Anyway, it can be seen that it was successful.
This method is very simple and crude. . Mark and share here. If you pass by and have a better way, or have suggestions, you can leave a comment. Thanks.
The above is the entire content of this article, I hope you all like it.