jpillora/node-edit-google-spreadsheet

Feature: Worksheet API

Open

#56 建立於 2015年1月26日

在 GitHub 查看
 (8 留言) (0 反應) (0 負責人)JavaScript (98 fork)github user discovery
enhancementhelp wanted

倉庫指標

Star
 (302 star)
PR 合併指標
 (PR 指標待抓取)

描述

Looking for Contributors Please look through these notes and then the source and if you decide to give this a shot, mention that you're working on this in the comments below and I'll give you push access.


A spreadsheet is the entire document, and a worksheet is a tab in the document. Currently this module models 1 spreadsheet and 1 worksheet, it should actually model N worksheets, just as spreadsheets do. The proposed feature would result in the API below. Please +1 below so we can gauge interest. I've specified a rough outline of the changes that need to be made, though they're subject to change.

A few initial notes:

  • Adding and deleting spreadsheets is out of scope, see the google-drive module
  • The metadata.js will be come worksheet.js since metadata is actually a worksheet API call
  • The Metadata class would be become a Worksheet class
  • On Spread.load all of the spreadsheets worksheets should be instantiated in spreadsheet.worksheets and if (now optional) worksheetName was set, then it would be set to spreadsheet.worksheet (the current worksheet).
  • Important To make this change backwards compatible spreadsheet.send()/receive() actually call spreadsheet.worksheet.send()/receive()
  • Finally, there's new APIs to add and remove worksheets
    • spreadsheet.load(title, callback(err, worksheet)) (If it's already in worksheets no request is needed, otherwise it will refresh the worksheet list. On success worksheet becomes the new current spreadsheet.worksheet)
    • spreadsheet.create(title, [numColumns, numRows], callback(err, worksheet)) (Operates as an "upsert" – adds if necessary. On success worksheet becomes the new current spreadsheet.worksheet)
    • spreadsheet.delete(title, callback(err))
    • As these calls are made spreadsheet.worksheets is being kept up to date

See prototype code:

Spreadsheet.load({
  username: creds.username,
  password: creds.password,
  spreadsheetName: 'node-edit-spreadsheet',
  worksheetName: 'Sheet1'  //worksheet becomes optional
}, function run(err, spreadsheet) {
  if(err) throw err;

  spreadsheet.worksheets === [ /* worksheet instances */, /* */ ];
  spreadsheet.worksheet === { /* Sheet1 instance */ };

  //now
  spreadsheet.send();
  spreadsheet.receive();
  //actually does
  spreadsheet.worksheet.send();
  spreadsheet.worksheet.receive();

  //and there's now 'load', 'create' and 'delete' methods

  spreadsheet.load("Sheet 3", function(err, worksheet) {
    //...
  });

  spreadsheet.create("Sheet 2", function(err, worksheet) {
    //...
  });

  spreadsheet.delete("Sheet 1", function(err) {
    //...
  });

});

貢獻者指南