Excel-to-json (Show Excel table data to the page)

Source: Internet
Author: User

Today, the boss gave me a demand, he needs to show the crawler crawling data on the page, because most of them are picture data, so my first reaction is to loop the spelling of the string

However, the data that the boss gave me is in the Excel table, so I need to convert the Excel table to a string. Find a lot of methods, are not appropriate, and finally found a NPM package called Excel-to-json package, now summarize.

First NPM Install Excel-to-json, then configure Package.json,

The Package.json is configured as follows

  

{    "name": "abc",    "version": "0.0.0", "    private": True,    "scripts": {        "start": "Node./bin/www"    },    "dependencies": {        "Xls-to-json": "*"    }}

Create a new A.js file with the following code configuration:

 

NODE_XJ = require ("Xls-to-json"); Node_xj ({    "test.xlsx",    "Output.json"   function(err, result) {    if  (err) {        console.error (err);     Else {        Console.log (result);    }});

Since the table file is xlsx, the suffix is changed above, and the output JSON file is directly to the root directory.

Then use node to run the A.js file and finally get a JSON file successfully. Done

Note here: This package will only convert the data in the table header, which means that if there is no table in the table, he will not convert.

Once you get the JSON data, you can loop through the string and then successfully show it!

Excel-to-json (Show Excel table data to the page)

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.