项目作者: abetomo

项目描述 :
Convert Google Spreadsheet contents to JSON. Also update Google spreadsheet from JSON data.
高级语言: JavaScript
项目地址: git://github.com/abetomo/node-ss2json.git
创建时间: 2017-05-30T02:05:40Z
项目社区:https://github.com/abetomo/node-ss2json

开源协议:MIT License

下载


node-ss2json

npm version
Test

Convert Google Spreadsheet contents to JSON.
Also update Google spreadsheet from JSON data.

install

  1. % npm install ss2json

help

  1. % ss2json --help
  2. Usage: ss2json [options] [command]
  3. Options:
  4. -V, --version output the version number
  5. -h, --help output usage information
  6. Commands:
  7. get [options]
  8. update [options]

get

  1. % ss2json get --help
  2. Usage: get [options]
  3. Options:
  4. -a, --auth [AUTH_JSON_FILE_PATH] JSON path for Google's authentication
  5. -i, --id [SPREADSHEET_ID] Google Spreadsheet ID
  6. -n, --name [SHEET_NAME] Sheet name in Google Spreadsheet
  7. -h, --help

update

  1. % ss2json update --help
  2. Usage: ss2json update [options]
  3. Options:
  4. -a, --auth [AUTH_JSON_FILE_PATH] JSON path for Google's authentication
  5. -i, --id [SPREADSHEET_ID] Google Spreadsheet ID
  6. -n, --name [SHEET_NAME] Sheet name in Google Spreadsheet
  7. -d, --data [DATA_JSON_FILE_PATH] JSON file path for update data
  8. --autoAddSheet Add when there was no sheet.
  9. -h, --help output usage information

Command example

Get the data from the spreadsheet and write it to data.json.

  1. % ss2json get \
  2. -a AUTH_JSON_FILE_PATH \
  3. -i SPREADSHEET_ID \
  4. -n SHEET_NAME > ./data.json

You can also edit data.json to update the spreadsheet.

  1. % ss2json update \
  2. -a AUTH_JSON_FILE_PATH \
  3. -i SPREADSHEET_ID \
  4. -n SHEET_NAME \
  5. -d ./data.json

Usage example of Node.js API

get

  1. const ss2json = new (require('ss2json'))()
  2. ss2json.convert({
  3. authJsonPath: 'JSON path for Google\'s authentication',
  4. spreadsheetId: 'Google Spreadsheet ID',
  5. sheetName: 'Sheet name in Google Spreadsheet'
  6. }).then((data) => {
  7. console.log(data)
  8. }).catch((err) => {
  9. console.error(err)
  10. })

update

  1. const ss2json = new (require('ss2json'))()
  2. ss2json.update({
  3. authJsonPath: 'JSON path for Google\'s authentication',
  4. spreadsheetId: 'Google Spreadsheet ID',
  5. sheetName: 'Sheet name in Google Spreadsheet',
  6. values: [
  7. // 'Update data'
  8. { key1: 'value1', key2: 'value2' },
  9. { key1: 'value3', key2: 'value4' },
  10. ...
  11. ],
  12. autoAdd: true // If true, the sheet will be added automatically if it doesn't exist.
  13. }).then((result) => {
  14. console.log(result)
  15. })

AUTH_JSON_FILE_PATH / authJsonPath

Use GCP service account credentials. You first need to create a service account, download its json key.