Es gibt viele Excel -Tabellen in der NodeJS -Vorlage. Hier werde ich kurz die Verwendung eines Moduls vorstellen, das ich verwendet habe.
Installieren Sie zuerst Excel -Module:
NPM Node-XLSX Installieren
Stellen Sie dann Module in den Code ein:
var xlsx = require ('node-xlsx');
Holen Sie sich schließlich die Daten und schreiben Sie sie an Excel:
var fs = required ('fs'); var xlsx = require ('node-xlsx'); var ajax = require ('./ Ajax.js'); start () function start () {ajax.ajax ({url: "http:/yuntuapi.amap.com/datam.datam: {oderdatam/datam/dataNage/data/list", ", Typ:", Typ: ", Typ:", Typ: ", Typ:", Typ: "," "Xxx", // 53EACBE4E4B0693FBF5FD13B Taste: "xxx"}, Funktion (Daten) {var mydatas = []; = []; datas.length - 1) {writexls (mydatas); fs.WriteFilesync ("Group.csv", Buffer, 'Binary');} Funktion parsexls () {var obj = xlsx.parse ('myFile.xlsx'); console.log (obj);}Ajax Teil des Codes:
var https = required ("https"); var http = required ("http"); var url = require ("url"); var queryString = require ('queryString'); // Standardwert var DefaultSeting = {// Wenn false zurückgegeben wird. '', // Objekt, String DataType: 'JSON', Fehler: function () {}, Header: {}, // {k: v, ...} Statuscode: {}, Erfolg: Funktion (data) {}, Timeout: 10, Typ: 'Get', // post url: www.baidu.com '}; ajaxlbs.js (Einstellungen) if (typeof -Einstellungen === "Objekt") {// Verwandte des Standardwert -Inheritanz // Todo ... für (Schlüssel in Standardsetting) {if (Einstellungen [Schlüssel] == NULL) {Einstellungen [Schlüssel] = DefaultSetting [Schlüssel]; }}}} var params = url.parse (Settings.Url, true); // Params parsed as follows // { // "protocol":"http:", // "slashes":true, // "host":"localhost:3000", // "port":"3000", // "hostname":"localhost", // "href":"http://localhost:3000/?d=1", // "Suche": "? D = 1", // "Abfrage": {"D": "1"}, // "Pathname": "/", // "Pfad": "/? D = 1" //} var options = {host: params.hostname, port: port: params.port || 80, Pfad: Params.Path, Methode: Settings.type}; if (settings.data! = null) {options.Path += "?" für (var key in setting.data) {options.path = options.Path + "&" + key + "=" + setting.data [Schlüssel]; } console.log (Optionen.Path); } var httpunity = http; if (params.Protocol == "https:") {options.port = 443; var httpunity = https; } var req = httpunity.request (Optionen, Funktion (res) {var data = ''; res.on ('data', function (chunk) {data += chunk;}). on ('end', function () {if (Einstellungen). Einstellungen.Success (Daten); false; //} //} if (settings.type === "post") {var datastr = queryString.stringify (Settings.data); req.setheader ("content-Length", datastr.length); req.write (datastr); } req.settimeout (setts.timeout); req.end ();} exports.ajax = ajax;Generierte Excel -Inhalte:
Quellcode -Download: NodeJS erhält Netzwerkdaten und generiert Excel -Tabellen
Das Obige dreht sich alles um diesen Artikel, ich hoffe, es wird für das Lernen aller hilfreich sein.