Existem muitas tabelas do Excel no modelo NodeJS. Aqui, apresentarei brevemente o uso de um módulo que usei.
Primeiro, instale módulos do Excel:
NPM Install Node-XLSX
Em seguida, introduza módulos no código:
var xlsx = requer ('node-xlsx');
Finalmente, obtenha os dados e escreva -os no Excel:
var fs = requer ('fs'); var xlsx = requer ('node-xlsx'); var ajax = requer ('. "XXX", // 53eAcBE4E4B0693FBF5FD13B Key: " nomes = [ == DataS.Length - 1) {writexls (myDatas); fs.writefilesync ("group.csv", buffer, 'binário');} função parsexls () {var obj = xlsx.parse ('myfile.xlsx'); console.log (obj);}Ajax parte do código:
var https = requer ("https"); var http = requer ("http"); var url = requer ("url"); var querystring = requer ('Querystring'); // Valor padrão var defaultSetting = {// se false é retornado, a solicitação pode ser cancelada) (function {// se Falsel); '', // objeto, string datatype: 'json', erro: function () {}, cabeçalhos: {}, // {k: v, ...} statusCode: {}, success: function (dados) {}, timeout: 10, type: 'get', // get, post url: "ww.baid.com"} {; ajaxlbs.js (Configurações) if (typeof Settings === "Object") {// lidera a herança do valor padrão // TODO ... para (chave no defaultSetting) {if (Settings [key] == NULL) {Settings [key] = defaultSetting [key]; }}}} var params = url.parse (Settings.url, true); // params analisou o seguinte // {// "protocolo": "http:", // "Slashes": true, // "host": "localhost: 3000", // "porta": "3000", // "hostName": "localhost", // "href": "http": http: //mildName ":" localhost ", //" href ":" http: http: //mildName ":" lochost ", //" href ":" http: http. "Search": "? D = 1", // "Query": {"d": "1"}, // "pathname": "/", // "path": "/? d = 1" //} var options = {host: params.hostname, porta: params.port || 80, caminho: params.path, método: Settings.Type}; if (Settings.data! = null) {options.path += "?" para (chave da var em configuração.data) {options.path = options.path + "&" + key + "=" + Settings.data [key]; } console.log (options.path); } var httpunity = http; if (params.protocol == "https:") {options.port = 443; var httpunity = https; } var req = httpunity.request (opções, function (res) {var data = ''; res.on ('dados', function (chunk) {data += chunk;}). ('end', function () {if (settings.datype == "json") {Try {data = json.se (dados. Settings.Success (Data); false; //} //} if (Settings.type === "post") {var datastr = querystring.Stringify (Settings.data); req.setheader ("Length-thength", Datatr.Length); req.Write (DatASTR); } req.setTimeout (Settings.Timeout); req.end ();} exports.ajax = ajax;Conteúdo do Excel gerado:
Download do código -fonte: Nodejs recebe dados de rede e gera tabelas do Excel
O exposto acima é tudo sobre este artigo, espero que seja útil para o aprendizado de todos.