-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.2.0 rewrite - now built-in auth, edit/add/deleting rows, major cod…
…e cleanup
- Loading branch information
Theo Ephraim
committed
Mar 4, 2013
1 parent
58583b5
commit 5a15dc3
Showing
7 changed files
with
344 additions
and
363 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var GoogleSpreadsheet = require("../index.js"); | ||
|
||
// only need to set the key once | ||
// auth can optionally be created and passed in as well | ||
var testsheet = new GoogleSpreadsheet( "0Araic6gTol6SdGtyUVAzQmVLM0lxUWlBMkNraWVubUE"); | ||
|
||
|
||
// If the spreadsheet is "published to web" then without authentication you can still get spreadsheet info and read rows - no editing | ||
// usually you probably wont need to call getInfo and can just read from sheets directly | ||
testsheet.getInfo( function(err, ss_info){ | ||
if (err) console.log( err ); | ||
|
||
console.log( ss_info.title + ' is loaded' ); | ||
|
||
// you can use the worksheet objects to add or read rows | ||
ss_info.worksheets[0].getRows( function(err, rows){ | ||
console.log( ss_info.worksheets[0].title + ' has '+rows.length + 'rows' ); | ||
}); | ||
}); | ||
|
||
|
||
|
||
// if auth is set, you can edit. you read the rows while authenticated in order to get the edit feed URLs from google | ||
testsheet.setAuth( 'youremail@gmail.com', 'YOURPASSWORD', function(err){ | ||
if (err) console.log(err); | ||
|
||
console.log(' GOOGLE AUTH SUCCESS!' ); | ||
|
||
// you can also add and read rows by just indicating the worksheet id (starts at 1) | ||
testsheet.addRow( 1, { | ||
testdate: (new Date()).toString('yyyy-MM-dd') | ||
}) | ||
|
||
testsheet.getRows( 2, function(err, rows){ | ||
if (err) console.log( err ); | ||
|
||
// to edit row data, just edit the data and call save() | ||
rows[0].testcount++; | ||
rows[0].save(); | ||
|
||
// you can also delete rows by calling .del() | ||
// rows[3].del(); | ||
}); | ||
|
||
}) |
Oops, something went wrong.