Use Node. js to convert Excel to JSON_node.js

Source: Internet
Author: User
This article records the use of node in personal projects. the js method and process for converting Excel to Json is very simple, practical, and detailed. Here we recommend it to anyone who needs it. I have been working on an online course selection system and have chosen node. js, which is popular nowadays. Today, I was thinking about how to import the student or teacher information into a large number of excel tables. I want to convert the excel file to json and then import it to mongodb.

I searched a lot of online materials. Most of them are C # or python. do you need to compile it yourself? do you need to run a variety of missing libraries. Google found that this module exists in node. The URL is https://www.npmjs.com/package/xls-to-json ..

Record the steps below:

To any location, create a package. json. I don't know why npm cannot be installed after I try it.

{ "name": "abc", "version": "0.0.0", "private": true, "scripts": {  "start": "node ./bin/www" }, "dependencies": {  "xls-to-json": "*" }}

Save the installation package and run npm install directly. Create 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 that is directly pasted. Then, when the sheet error occurs, I directly comment it out.

Put test.xls in the same directory, and then click node app. js ..

The information of all the students is coded. We can see that it is successful.

This method is very simple and crude .. Mark and share here. there is a better way to pass by, or I suggest you leave a comment. Thank you.

The above is all the content of this article. I hope you will like it.

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.