Workaround for XLS direct to JSON

Source: Internet
Author: User

Hello everyone, here's how XLS turns JSON.

1, directly with the XLS tool can be transferred out of JSON (this is not introduced).

2, using the NODEJS program to perform the above JSON conversion operation, I use the Nodejs version is 4.2.2, the following paste all the code:

  

//File Upload//Gets the current time (month, day, minute, and seconds)functionGetnow () {varDate =NewDate (); varSeperator1 = ""; varSeperator2 = ""; varmonth = Date.getmonth () + 1; varStrdate =date.getdate (); if(Month >= 1 && month <= 9) {Month= "0" +month; }    if(strdate >= 0 && strdate <= 9) {strdate= "0" +strdate; }    varcurrentdate = date.getfullyear () + seperator1 + month + Seperator1 +strdate+ "" + date.gethours () + Seperator2 +date.getminutes ()+ Seperator2 + date.getseconds () +date.getmilliseconds (); returncurrentdate;}//Service StartvarExpress = require (' Express ');varApp =Express ();varFS = require ("FS");varHTTP = require (' http ');var$ = require ("jquery");varxlsx = require ("node-xlsx");//Use is JSONvarjson=NULL;varBodyparser = require (' Body-parser '));varMulter = require (' Multer ')); App.use (Express.static (' Public ') ); App.use (bodyparser.urlencoded ({extended:false}); App.use (Multer ({dest:'/tmp/'}). Array (' image ')); App.get ('/index.html ',function(req, res) {Res.sendfile (__dirname+ "/" + "index.html" );}); App.post ('/file_upload ',function(req, res) {varNamelast=getnow () + req.files[0].originalname; varDes_file = __dirname + "/files/" +Namelast; Fs.readfile (req.files[0].path,function(err, data) {//300M File Limit       if(314572800<data.length) {response={code:15, msg:' File length is Max ', Data:"", Path:"", name:req.files[0].originalname};       Res.end (json.stringify (response)); }       Else{            //Write FileFs.writefile (des_file, data,function(err) {if(Err) {Console.log (err); }Else{JSON=Xlsx.parse (Des_file); Response={code:0, msg:' File uploaded successfully ', Data:JSON.stringify (JSON), Path:namelast, Name:re q.files[0].originalname}; Fs.writefile ("Json.json", Json.stringify (JSON),function(err) {if(ERR)Throwerr;              });            } res.end (Json.stringify (JSON));       }); }    });}); varServer = App.listen (3000,function() {Console.log ("address:http://localhost:3000");});

Alternate address/demo:http://182.92.155.97:3000/index.html

How to use: Open the address, click the Upload Upload button to select the *.xls file upload, JSON data directly displayed on the page, of course, "Ctrl + a" all selected JSON:

END

Workaround for XLS direct to JSON

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.