Home > Web Front-end > JS Tutorial > body text

Node.js implements Excel conversion to JSON_node.js

WBOY
Release: 2016-05-16 16:02:34
Original
1090 people have browsed it

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": "*"

 }
}

Copy after login

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);
  }
 });
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!