Hay muchas tablas de Excel en la plantilla NodeJS. Aquí presentaré brevemente el uso de un módulo que he usado.
Primero, instale módulos de Excel:
NPM Instalar nodo-xlsx
Luego, introduzca módulos en el código:
var xlsx = require ('node-xlsx');
Finalmente, obtenga los datos y escríbelo a Excel:
var fs = require('fs');var xlsx = require('node-xlsx');var ajax = require('./ajax.js');start();function start() { ajax.ajax({ url: "http://yuntuapi.amap.com/datamanage/data/list", type: "GET", data: { tableid: "Xxx", // 53AcBe4e4b0693fbf5fd13b clave = []; DataS.length - 1) {writexls (myDatas);}} console.log (myDatas.length); fs.WriteFilesync ("Group.csv", buffer, 'binary');} function parsexls () {var obj = xlsx.parse ('myfile.xlsx'); console.log (obj);}Ajax parte del código:
var https = require ("https"); var http = require ("http"); var url = require ("Url"); var QueryString = require ('QueryString'); // Valor predeterminado Var Defaultsetting = {// Si False se devuelve, la solicitud se puede cancelar Beforefess: Function (Req) {}, Complete: Complete: Function (Function (}, los datos:}, los datos: los datos) '', // Object, String DataType: 'json', error: function () {}, encabezados: {}, // {k: v, ...} statusCode: {}, éxito: function (data) {}, timeout: 10, type: 'get', // get, publica url: "www.baidu.com"};/** * * */function aJax (settings) ajaxlbs.js (configuración) if (typeof settings === "objeto") {// manejar la herencia de valor predeterminado // toDo ... para (key en defaultSetting) {if (configuración [key] == null) {configuración [key] = defaultSetting [key]; }}}} var params = url.parse (settings.url, true); // params analizados como sigue // {// "protocolo": "http:", // "slashes": true, // host ":" localhost: 3000 ", //" puerto ":" 3000 ", //" hostname ":" localhost ", //" href ":" http: // localhost: 3000/? D = 1 ", ///////// "Buscar": "? D = 1", // "Query": {"D": "1" "}, //" PathName ":"/", //" Path ":"/? D = 1 "//} var options = {host: params.hostName, port: params.| 80, ruta: params.path, método: settings.type}; if (settings.data! = null) {options.path += "?" For (varilla var en settings.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 (options, function (res) {var data = ''; res.on ('data', function (chunk) {data += chunk;}). on ('end', function () {if (settates.datatype === "JSON") {intent {data = json.parse (data);} Catch (e); settings.success (data); return false; //} //} if (settings.type === "post") {var dataTR = QueryString.Stringify (settings.data); req.setheader ("Content-longitud", dataTastr.length); req.write (dataTastr); } req.setTimeout (settings.timeout); req.end ();} exports.AJAX = AJAX;Contenido de Excel generado:
Descarga del código fuente: NodeJS obtiene datos de red y genera tablas de Excel
Lo anterior se trata de este artículo, espero que sea útil para el aprendizaje de todos.