NODEJS middleware Xlsx.js Export Excel file using method Encapsulation (original)

Source: Internet
Author: User

Previous projects have been using the Nodejs node-xlsx.js middleware, the most recent project deployment can not use the external network, and node-xlsx.js path is too long cannot be copied, now use Xlsx.js middleware.

Now to share your own encapsulation of the use of the way to learn with everyone.

The code is simple and lightly sprayed.

/** * Created by Administrator on 2016/11/17. * Using XLSX Middleware, incoming header [array], in-table data [object array], file name [string]//var header=["name", ' age ', ' gender ']; * var excel=[{name: ' Z3 ', age:16,sex: ' Man '}, {name: ' L4 ', Age:20,sex: ' Female '}, {name: ' W5 ', age:24,sex: ' Man '}, {name: ' Z6 ', age:23, Sex: ' Female '}, {name: ' ss ', Age:10,sex: ' No male no female '}]; var path= '. /web/xxx.xlsx '; */var fs=require (' FS '), var os=require (' OS '), var xlsx=require (' xlsx '), var errors=require ('.. /libs/errors '), var underscore = require (' underscore '), function Createexcel (headarr,excel,filepath,callback) {if (! Headarr instanceof Array | | !excel instanceof Array | |        typeof FilePath! = ' string ') {//console.log (Headarr instanceof Array, Excel instanceof array,typeof filePath);    Return callback ("parameter pass error required to create file method", null);        }else{var arrlen=headarr.length; var headobj={},//generate table header indexobj={};//generate table data for (Var i=0;i<arrlen;i++) {var STR=STRING.FROMC            Harcode (65+i) +1; if (i>26) {Str=string.fromcharcode (+) +string.fromCharCode (65+i-26) +1;            } if (i>52) {return callback (' table header too much, please do appropriate deletions ', null);        } Headobj[str]={v:headarr[i]};        } var indexarr=[]; for (Var e=0;e<excel.length;e++) {for (Var j=0;j

  

NODEJS middleware Xlsx.js Export Excel file using method Encapsulation (original)

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.