根据网站https://www.twilio.com/blog/2017/03/google-spreadsheets-and-javascriptnode-js.html,您需要从Google API控制台创建服务帐户和OAuth2凭据。我已完成创建服务帐户并在电子表格中具有OAuth2凭据。当我尝试使用代码和命令节点电子表格sheets.js运行JS文件时
var GoogleSpreadsheet = require('google-spreadsheet');
var creds = require('./client_secret.json');
// Create a document object using the ID of the spreadsheet - obtained from its URL.
var doc = new GoogleSpreadsheet('*spreadsheet ID*');
// Authenticate with the Google Spreadsheets API.
doc.useServiceAccountAuth(creds, function (err) {
// Get all of the rows from the spreadsheet.
doc.getRows(1, function (err, rows) {
console.log(rows);
});
});
它显示以下错误消息:
Error: Cannot find module 'google-spreadsheet'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (C:\Users\User\Desktop\spreadsheet.js:1:87)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)