1. To export the Excel format for Nodejs server-side operational data
Excel-export Package Address:https://github.com/functionscope/Node-Excel-Export
Introduction to How to use:(used as an example in the Express framework)
var express = require (' Express '), var nodeexcel = require (' Excel-export '), var app = Express (), App.get ('/excel ', function ( Req, res) {var conf ={}; Conf.stylesxmlfile = "Styles.xml"; Conf.cols = [{caption: ' String ', type: ' String ', beforecellwrite:function (row, celldata) { return Celldata.touppercase (); }, width:28.7109375},{caption: ' Date ', type: ' Date ', beforecellwrite:function () { var origindate = new Date (DATE.UTC (1899,11,30)); return function (row, Celldata, eopt) {if (eopt.rownum%2) {eopt.styleindex = 1; } else{Eopt.styleindex = 2; } if (celldata = = = null) {Eopt.celltype = ' string '; Return ' n/a '; } else return (celldata-origindate)/(24 * 60 * 60 * 1000); }} ()},{caption: ' BoOl ', type: ' bool '},{caption: ' Number ', type: ' number '}]; Conf.rows = [[' Pi ', new Date (DATE.UTC (4, 1)), true, 3.14], ["E", new Date (4, 1), False, 2.7182] , ["M&m<> '", New Date (DATE.UTC (6, 9)), False, 1.61803], ["null Date", NULL, True, 1.414] ]; var result = Nodeexcel.execute (conf); Res.setheader (' Content-type ', ' application/vnd.openxmlformats '); Res.setheader ("Content-disposition", "attachment; Filename= "+" report.xlsx "); Res.end (result, ' binary ');}); App.listen (Console.log); (' Listening on Port 3000 ');
Well, it's cool to use, it's simple.
Try this example, the resulting Excel result is:
When used, there is a small reminder that the current JS run path must be added Style.xml file Ah, the source can be copied from the Excel-export package.
OK, done, so convenient so easy!
Introduction to Excel-export usage in Nodejs