Node.js to realize Excel turn Json_node.js

Source: Internet
Author: User
Tags json

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.

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.