基于 Node.js 的 Google Spreadsheets 数据读取

本项目提供一个 Node.js 模块,用于快速读写 Google Spreadsheets 电子表格数据。

快速开始

  1. 克隆或下载项目代码:

bash

git clone https://github.com/keitalab/google_spreadsheet_for_node.js.git

或直接下载项目 ZIP 文件。

  1. 安装依赖:

bash

npm install

  1. 获取 Google Cloud Platform 凭据:

  2. 在 Google Cloud Console 中启用 Google Drive API。

  3. 创建服务帐户并下载 JSON 格式的凭据文件。

  4. 代码示例:

```javascript

const { GoogleSpreadsheet } = require('google-spreadsheet');

// 替换为您的凭据文件路径

const creds = require('./path/to/your/credentials.json');

// 替换为您的电子表格 ID

const spreadsheetId = 'your-spreadsheet-id';

async function accessSpreadsheet() {

const doc = new GoogleSpreadsheet(spreadsheetId);

await doc.useServiceAccountAuth(creds);

await doc.loadInfo();

console.log(doc.title);

// 进一步操作,例如读取或写入单元格数据

}

accessSpreadsheet();

```

注意: 将代码中的占位符替换为您的实际值。

zip 文件大小:5.07KB