Instead of upgrading this old Google Spreadsheets module to support the Google Sheets v4 API, I've chosen to deprecate it, and provide a guide on how to use the googleapis
module directly. The googleapis
module, along with the Sheets v4 API provides:
- Faster responses
- More features
- Uses JSON instead of XML
async
/await
support
Please see this new repository for more information
A simple API for reading and writing Google Spreadsheets in Node.js
This module aims to be a complete wrapper around the Google Sheets API version 3.0. If anything is missing, create an issue, or even better, a pull request.
npm install edit-google-spreadsheet
Load a spreadsheet:
var Spreadsheet = require("edit-google-spreadsheet");
Spreadsheet.load(
{
debug: true,
spreadsheetName: "edit-spreadsheet-example",
worksheetName: "Sheet1",
// Choose from 1 of the 5 authentication methods:
// 1. Username and Password has been deprecated. OAuth2 is recommended.
// OR 2. OAuth
oauth: {
email: "[email protected]",
keyFile: "my-private-key.pem"
},
// OR 3. OAuth2 (See get_oauth2_permissions.js)
oauth2: {
client_id: "generated-id.apps.googleusercontent.com",
client_secret: "generated-secret",
refresh_token: "token generated with get_oauth2_permission.js"
},
// OR 4. Static Token
accessToken: {
type: "Bearer",
token: "my-generated-token"
},
// OR 5. Dynamic Token
accessToken: function(callback) {
//... async stuff ...
callback(null, token);
}
},
function sheetReady(err, spreadsheet) {
//use speadsheet!
}
);
Note: Using the options spreadsheetName
and worksheetName
will cause lookups for spreadsheetId
and worksheetId
. Use spreadsheetId
and worksheetId
for improved performance.
Update sheet:
function sheetReady(err, spreadsheet) {
if (err) throw err;
spreadsheet.add({ 3: { 5: "hello!" } });
spreadsheet.send(function(err) {
if (err) throw err;
console.log("Updated Cell at row 3, column 5 to 'hello!'");
});
}
Read sheet:
function sheetReady(err, spreadsheet) {
if (err) throw err;
spreadsheet.receive(function(err, rows, info) {
if (err) throw err;
console.log("Found rows:", rows);
// Found rows: { '3': { '5': 'hello!' } }
});
}
All functions which have a callback
return a Promise
tied
to that callback and can therefore be used with async
/ await
.
const Spreadsheet = require("../");
(async function example() {
let spreadsheet = await Spreadsheet.load({
debug: true,
oauth2: ...,
spreadsheetName: "node-spreadsheet-example",
worksheetName: "Sheet1"
});
//receive all cells
let [rows, info] = await spreadsheet.receive({getValues: false});
console.log("Found rows:", rows);
console.log("With info:", info);
})().catch;
Get metadata
function sheetReady(err, spreadsheet) {
if (err) throw err;
spreadsheet.metadata(function(err, metadata) {
if (err) throw err;
console.log(metadata);
// { title: 'Sheet3', rowCount: '100', colCount: '20', updated: [Date] }
});
}
Set metadata
function sheetReady(err, spreadsheet) {
if(err) throw err;
spreadsheet.metadata({
title: 'Sheet2'
rowCount: 100,
colCount: 20
}, function(err, metadata){
if(err) throw err;
console.log(metadata);
});
}
WARNING: all cells outside the range of the new size will be silently deleted
Batch edit:
spreadsheet.add([[1, 2, 3], [4, 5, 6]]);
Batch edit starting from row 5:
spreadsheet.add({
5: [[1, 2, 3], [4, 5, 6]]
});
Batch edit starting from row 5, column 7:
spreadsheet.add({
5: {
7: [[1, 2, 3], [4, 5, 6]]
}
});
Formula building with named cell references:
spreadsheet.add({
3: {
4: { name: "a", val: 42 }, //'42' though tagged as "a"
5: { name: "b", val: 21 }, //'21' though tagged as "b"
6: "={{ a }}+{{ b }}" //forumla adding row3,col4 with row3,col5 => '=D3+E3'
}
});
Note: cell a
and b
are looked up on send()
See Options below
Add cells to the batch. See examples.
Sends off the batch of add()
ed cells. Clears all cells once complete.
options.autoSize
When required, increase the worksheet size (rows and columns) in order to fit the batch - NOTE: When enabled, this will trigger an extra request on every send()
(default false
).
Recieves the entire spreadsheet. The rows
object is an object in the same format as the cells you add()
, so add(rows)
will be valid. The info
object looks like:
{
spreadsheetId: 'ttFmrFPIipJimDQYSFyhwTg',
worksheetId: 'od6',
worksheetTitle: 'Sheet1',
worksheetUpdated: '2013-05-31T11:38:11.116Z',
authors: [ { name: 'jpillora', email: '[email protected]' } ],
totalCells: 1,
totalRows: 1,
lastRow: 3
}
options.getValues
Always get the values (results) of forumla cells.
Get and set metadata
Note: when setting new metadata, if rowCount
and/or colCount
is left out,
an extra request will be made to retrieve the missing data.
The raw data recieved from Google when enumerating the spreedsheet and worksheet lists, which are triggered when searching for IDs. In order to see this array of all spreadsheets (raw.spreadsheets
) the spreadsheetName
option must be used. Similarly for worksheets (raw.worksheets
), the worksheetName
options must be used.
Function returning the authenticated Spreadsheet instance.
If true
, will display colourful console logs outputing current actions.
Google account - Be careful about committing these to public repos.
OAuth configuration object. See google-oauth-jwt. By default oauth.scopes
is set to ['https://spreadsheets.google.com/feeds']
(https
if useHTTPS
)
Reuse a generated access token
of the given type
. If you set accessToken
to an object, reauthentications will not work. Instead use a function accessToken(callback(err, token)) { ... }
function, to allow token generation when required.
The spreadsheet you wish to edit. Either the Name or Id is required.
The worksheet you wish to edit. Either the Name or Id is required.
Whether to use https
when connecting to Google (default: true
)
Return text values for cells or return values as typed. (default: true
)
- Create New Spreadsheets
- Read specific range of cells
- Option to cache auth token in file
- Q: How do I append rows to my spreadsheet ?
- A: Using the
info
object returned fromreceive()
, one could always beginadd()
ing at thelastRow + 1
, thereby appending to the spreadsheet.
Thanks to googleclientlogin
for easy Google API ClientLogin Tokens
BTC 1AxEWoz121JSC3rV8e9MkaN9GAc5Jxvs4
Copyright © 2015 Jaime Pillora <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node-edit-google-spreadsheet's People
Forkers
touchlocal garaboncias raadad ivanguardado ro-ka haudv crindt simonmudd pelayobesa matthojo webds web5design mxmz melodylife spllr twistedstream adi2412 colinhicks sejas danboy alex-repos loosemoose twinehealth bohdan-anderson jasonhargrove suguru03 zeitos nillu hackfrag pingflow tylerstalder glynnbird zaru jleplomet ejb ssimono maeldur ubik2 gnihi thomue00 mz2 sjwilliams yoshiya0503 kobarei fzac markitx tillerhq verdier tlvince krebbl anilkp2005 msylvia krizka shoikot andrewsem mirkods co-b dburner createdbysk jovibizstack cybic rudymalhi hughepaul matterantimatter integral jacobdr noahjs gowthaman-murugan tasogarepg flyeven laurilehmijoki coobaha chalcedonyt philipdavis lynxaegon mhtkmr54 contolini bradparks rasata offirmo audienseco mit9 petrumagdeleine devayansarkar cjroth prasad83 yamadakazuyuki ahtoh874 kumarshubham112 pookismahi zhencc1023 mahinsha87 luisjuarrosnode-edit-google-spreadsheet's Issues
Text cells starting with a numeric character get interpreted as a numeric formatted cell
Hello,
We have an issue with node-edit-google-spreadsheet.
This cell in our google spreadsheet:
1. March 2011: Protests begin
Get changed into this:
1
But when we change the cell to this:
hello 1. March 2011: Protests begin
It outputs correctly.
Are you able to fix this or recommend a solution?
This node project is really good, we're using it at the BBC to help us make the News website. :-)
Thanks,
Steve C & Tom M.
Newlines get lost when saving cells
_.escape() doesn't encode newlines, so they get lost in the value field of the cell and interpreted as a space.
Feature: Worksheet API
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 comeworksheet.js
since metadata is actually a worksheet API call - The
Metadata
class would be become aWorksheet
class - On
Spread.load
all of the spreadsheets worksheets should be instantiated inspreadsheet.worksheets
and if (now optional)worksheetName
was set, then it would be set tospreadsheet.worksheet
(the current worksheet). - Important To make this change backwards compatible
spreadsheet.send()/receive()
actually callspreadsheet.worksheet.send()/receive()
- Finally, there's new APIs to add and remove worksheets
spreadsheet.load(title, callback(err, worksheet))
(If it's already inworksheets
no request is needed, otherwise it will refresh the worksheet list. On successworksheet
becomes the new currentspreadsheet.worksheet
)spreadsheet.create(title, [numColumns, numRows], callback(err, worksheet))
(Operates as an "upsert" – adds if necessary. On successworksheet
becomes the new currentspreadsheet.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) {
//...
});
});
Using a variable as a row or column number
Is it possible to assign a variable to a column or row number in order to have the row that data is input to change every time a script is run.
Get raw CSV
Hi,
Any chance edit-google-spreadsheet could just return the raw CSV file from Google API instead of converting it to JSON?
Thanks, this project has really helped me.
/t
Native module compilation errors
Bug: Had reports via email recounting native module compilation errors due to node-expat
, which is used by the current XML parser. If this is a big issue, we can apply @ubik2's patch https://gist.github.com/ubik2/95d18f849b7b2878e4e0.
Query support?
Is there support for queries, e.g. to retrieve only a given row of a worksheet?
Need to migrate to Drive API before April 20, 2015
Google recently communicated that Documents List API will be discontinued on April 20, 2015. This change means that service calls for this API will no longer be supported, and any Google Apps features that are implemented using this API will no longer function.
One of the URL's that will be discontinued is https://spreadsheets.google.com/feeds/ which is used by this module. It's suggested to migrate to the Drive API.
To summarize, node-edit-google-spreadsheet will no longer function as of April 20, 2015 if no action is taken.
Way to create new spreadsheet
I'd like to create new spreadsheet with this library. but it seems not supported yet...
Feature: Row API (List-based Feeds)
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.
Currently, this module only uses cell-based feeds, though there is also a row-based REST API: https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds. I haven't researched too deep into the REST API, though I think it would result in a module API like:
//add a new 'row' property
spreadsheet.rows.get(function(err, rows) {
//get all rows
});
spreadsheet.rows.query({my:"query"}, function(err, rows) {
//get specific rows
});
spreadsheet.rows.add({name:"foo",age:25}, function(err, newRow) {
//insert a row
});
//each of the row objects above have:
row.update({name:"bar"}, function(err) {
//updates this row inplace
});
row.delete(function(err) {
//deletes this row and shifts up
});
Read through the docs and comment on the proposed API above, I may have missed something.
If the worksheets API feature is also being done, the rows
object would a go inside each worksheet
, and then be aliased from spreadsheet
.
On send(), getting TypeError: Object #<Object> has no method 'indexOf' on result.indexOf() call
[grunt-develop] > TypeError: Object #<Object> has no method 'indexOf'
at /Users/username/dev/canvas_test/node_modules/edit-google-spreadsheet/lib/index.js:403:19
at Request._callback (/Users/username/dev/canvas_test/node_modules/edit-google-spreadsheet/lib/index.js:122:12)
at Request.self.callback (/Users/username/dev/canvas_test/node_modules/edit-google-spreadsheet/node_modules/request/index.js:148:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/Users/username/dev/canvas_test/node_modules/edit-google-spreadsheet/node_modules/request/index.js:876:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/Users/username/dev/canvas_test/node_modules/edit-google-spreadsheet/node_modules/request/index.js:827:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickDomainCallback (node.js:459:13)
application exited with code 8
I have v0.2.9 installed and when I call the following from the example, I get the above error:
spreadsheet.add({ 3: { 5: "hello!" } });
spreadsheet.send(function(err) {
if(err) throw err;
console.log("Updated Cell at row 3, column 5 to 'hello!'");
res.send('YAY!');
});
It looks like 'result' in the 'send()' method has changed.
Problem with iojs 1.5.1
I am using your package in my app, which i now want to run on iojs... however i get this error. Maybe its more xml2json/node-expat related, if so i am sorry :-)
Error: /app/node_modules/edit-google-spreadsheet/node_modules/xml2json/node_modules/node-expat/build/Release/node_expat.node: undefined symbol: _ZN2v811HandleScope12CreateHandleEPNS_8internal10HeapObjectE
at Error (native)
at Module.load (module.js:339:32)
at Function.Module._load (module.js:294:12)
at Module.require (module.js:349:17)
at require (module.js:368:17)
at Object. (/app/node_modules/edit-google-spreadsheet/node_modules/xml2json/node_modules/node-expat/lib/node-expat.js:4:13)
at Module._compile (module.js:444:26)
at Object.Module._extensions..js (module.js:462:10)
at Module.load (module.js:339:32)
at Function.Module._load (module.js:294:12)
Can't read string values
I am getting 0 instead of expected string from spreadsheet. What I am doing wrong?
Found rows: { '1': { '1': '1243', '2': '555', '3': 0 } }
Info: { spreadsheetId: 'dsds',
worksheetId: 'od6',
worksheetTitle: 'Sheet1',
worksheetUpdated: Wed Feb 12 2014 22:56:33 GMT+0700 (ICT),
totalCells: 3,
totalRows: 1,
lastRow: 1,
nextRow: 2 }
Using parseFloat on strings causes IP addresses and other strings to be interpreted incorrectly
/lib/util.js
if(typeof obj === 'string') {
var res = parseFloat(obj, 10);
if(isNaN(res)) return obj;
return res;
}
This code makes an IP address such as '192.168.1.1' be interpreted as a float 192.168, making the returned data unusable.
New Sheets support
Decided to switch to the New Sheets version but it turned out that the wonderful node module doesn't support New Sheets yet.
Are there lots of changes involved to implement it?
Thanks
"Google Client Login Error: Login Failed" since 2015/5/26
Hi, all
I have encountered error message "Google Client Login Error: Login Failed" since 2015/5/26.
I use "Username and Password" authentication, the google account & password are not misspelled, I can use them to login and retrieve spreadsheet data normally before 2015/5/26.
Any help will be greatly appreciated :)
confirm: correct list based feeds not supported?
Just to confirm after looking at the code: is it correct that list based feeds are not supported?
preserve empty cells
When rows
get returned empty cells from spreadsheet are discarded. Is there a way to preserve them? As you can see below we're missing cell 3
. Thanks again.
'5':
{ '1': 3,
'2': 'tag',
'4': 'new item',
'6': 'test',
'7': 'Long name',
'8': 'index',
'9': 'try command',
...
On sheetReady with incorrect spreadsheetId returns non-json string
When you try to load a sheet with a incorrect spreadsheetId, like shown underneath, the callback is called with a weird err argument
var Spreadsheet = require('edit-google-spreadsheet');
Spreadsheet.load({
spreadsheetId: '1234565464',
worksheetName: 'Sheet1',
username: '[email protected]',
password: 'my-5uper-t0p-secret-password'
}, function sheetReady(err, spreadsheet) {
if (err)
console.log('err', err)
});
This is output in the console
Failed to parse JSON response: 'SyntaxError: Unexpected token T':
The spreadsheet at this URL cannot be found...
When I debug lib/index.js line 93, I see that the body of the response is plain text and no JSON, so it should not be parsed.
The spreadsheet at this URL cannot be found...
BTW: the status of the response is not 200 but 400 in this case (because it's a wrong spreadsheetId that cannot be found) and. We can use that to change a few lines in lib/index.js to handle the non-json result on error.
try {
result = JSON.parse(body);
} catch(err) {
return callback("Failed to parse JSON response: '"+err+"':\n"+body, null);
}
should become:
try {
result = JSON.parse(body);
} catch(err) {
if (response.status!= 200)
return callback(body);
else
return callback("Failed to parse JSON response: '"+err+"':\n"+body, null);
}
I guess that the current url spreadsheets.google.com/feeds/ used in this module (line 86 in lib/index.js) returns plain strings as errors that are non-json by default. However I can't find the documentation to back that up.
getValues option not getting passed correctly to util.gcell2cell (spreadsheet.js: 510)
this line in spreadsheet.js (510):
rows[r][c] = util.gcell2cell(cell, options.getValues, _this.opts.useCellTextValues);
the second parameter should be:
_this.opts.getValues
corrected line:
rows[r][c] = util.gcell2cell(cell, _this.opts.getValues, _this.opts.useCellTextValues);
I love this module. Thanks!
Accessing a document with OAuth
I have used oauth with keyFile and was unable to access a document in my developer user's Drive.
Then I realized that the file should be shared with the Google generated email address.
The option for authentication:
oauth: {
email: '[email protected]',
keyFile: 'key.pem'
}
When I shared the document with [email protected]
the issue is resolved, I was able to interact with the spreadsheet.
Just wanted to point out that this may go into the documentation for the ease of use.
{getValues:true} not evaluating REGEXREPLACE
I've got a number of cells in my sheet that use REGEXREPLACE(...) to create their contents from a combination of other cells (and replacing spaces with - characters, making everything lower-case, etc.), and those regexes aren't being evaluated during export even if {getValues:true}
is set. Is this expected behavior or is there another option that I'm missing? These cells export just fine with a manual File > Download as... > CSV from within the Google doc itself, but I'd really like to automate this process. Any ideas on how I could pull this off?
Request does not follow 302 redirects from Google
Hello and thanks to Jaime Pillora and the other contributors for the great module!
I ran into an issue recently where Google is frequently returning a 302, and the request code in the module would return the response body as an error to my code.
For instance, after adding cells, when I would call .send(), I would see 'Sending updates...' from the debug logging, but then my callback would be called with an HTML body that contained common 'Moved Temporarily' text. I dug in a little bit, and Google was responding to a POSTs to /feeds/cells/1-QPKWX_kQVs3LmHY3djpDZ0qVjTPUHMgs-G4NLQ0ksc/od6/private/full/batch with a 302 redirect with location header of /feeds/cells/1-QPKWX_kQVs3LmHY3djpDZ0qVjTPUHMgs-G4NLQ0ksc/od6/private/full/batch**?lsrp=1**
The gist is that Google is apparently redirecting to add lsrp=1 as a query string, but we are treating the redirect like an error.
I locally modified the Spreadsheet.prototype.request in lib/index.js to follow the redirect, and now it works just fine.
I'm a little suspicious of my fix only because it happens very frequently for me, yet I didn't see anyone else having this same issue, but it makes sense to me and I'm happy to create a PR as soon as I figure out how to create a PR... I Googled around for information on the lsrp query string parameter, but came up empty, and I'm wondering if anyone else knows what that's for as well (perhaps, for example, in addition the redirect fix, it could be appropriate to append that query string to the URL in the original POST).
Has anyone else seen very common redirects from Google when POSTing batches of cell updates like that?
I also see a surprisingly high number of 500's from Google as well, but those seem to be more transient and much less reproducible. Separate issue, but I'm curious if anyone else is seeing the same thing.
- Tim
JSON Parse Error: SyntaxError: Unexpected end of input
I am getting this error after google login and spreadsheet searching has been done. Please help me out.
app.get('/lead', function(req, res){
console.log(req.query.fullname);
Spreadsheet.load({
debug: true,
spreadsheetId: '*_',
worksheetName: 'Sheet1',
// Choose from 1 of the 3 authentication methods:
// 1. Username and Password
username: '[email protected]',
password: '_',
// OR 2. OAuth
// oauth : {
// email: '[email protected]',
// keyFile: 'my-private-key.pem'
// },
// // OR 3. Token
// accessToken : {
// type: 'Bearer',
// token: 'my-generated-token'
// }
}, function sheetReady(err, spreadsheet) {
if(err) throw err;
spreadsheet.add({ 3: { 5: "Anurag Prasad" } });
spreadsheet.send(function(err) {
if(err) throw err;
console.log("Updated Cell at row 3, column 5 to 'hello!'");
});
});
});
Question: getting computed formula values, not the formula
Hi,
I was reading the API docs here: https://developers.google.com/google-apps/spreadsheets/data
and noticed that the XML can provide two values: inputValue and numericValue.
I've managed to authenticate with OAuth2 successfully, and have a basic setup similar to the example in the docs:
spreadsheet.load({
debug: true,
spreadsheetId: '1bgsoZX7NDQML_LC9yHpH_StDUDrX4NmmKX7pVJGKnrg',
worksheetId: 'oa9va38',
oauth2: {
/* jshint camelcase: false */
client_id: auth.clientID,
client_secret: auth.clientSecret,
refresh_token: auth.refreshToken
},
useCellTextValues: true
}, function (err, spreadsheet) {
if(err) {throw err;}
spreadsheet.receive(function(err, rows, info) {
if(err) {throw err;}
console.log('Found rows:', rows);
return rows;
});
});
However in the console, all I am getting are the literal formulas, not the computed values. I assumed that the useCellTextValues option flag switches between them, but it doesn't seem to change the output. Can you help?
Otherwise, is there any other way to get the numericValue?
Creating a new spreadsheet ?
Is edit-google-spreadsheet has any api to add a new sheet ?
spreadsheet.add Giving error
spreadsheet.add Giving error
Cannot Call Method 'add' of null
Add method, columns and rows from variable.
Hello. First of all. Great work, but i ended up spending to many time on this due to one probably mine issue that i ask you to help me.
First time with node. I managed to write to the google sheet, but i want to append data. I want to say to the method that it will write let´s say, variable x that stores the col, variable y that stores the row like this spreadsheet.add{x:{y:"test"}}
Thank you very much.
Undefined response throwing error
Occasionally I'm seeing the following error being thrown. Unfortunately I'm not sure what the actual error request is returning.
TypeError: Cannot read property 'statusCode' of undefined\n at Request._callback (node_modules/edit-google-spreadsheet/lib/index.js:376:16)\n at self.callback (node_modules/edit-google-spreadsheet/node_modules/request/index.js:148:22)\n at Request.EventEmitter.emit (events.js:95:17)\n at ClientRequest.self.clientErrorHandler (node_modules/edit-google-spreadsheet/node_modules/request/index.js:257:10)\n at ClientRequest.EventEmitter.emit (events.js:95:17)\n at CleartextStream.socketErrorListener (http.js:1547:9)\n at CleartextStream.EventEmitter.emit (events.js:95:17)\n at Socket.onerror (tls.js:1445:17)\n at Socket.EventEmitter.emit (events.js:117:20)\n at net.js:441:14\n","time":"2014-03-08T08:19:19.936Z","v":0}
Looks like https://github.com/jpillora/node-edit-google-spreadsheet/blob/stable/lib/index.js#L376 is checking the response first before checking if an error is returned.
Google Documents List API is being deprecated | Migrate to Drive
Warning: The deprecation period for Version 3 of the Google Documents List API is nearly at an end.
On April 20, 2015, we will discontinue service for this API. This means that service calls to the API are
no longer supported, and features implemented using this API will not function after April 20, 2015.
You must migrate to the Drive API as soon as possible to avoid disruptions to your application.
Posible solution: migrate to drive
Getting specific entry from rows
I was wondering how do you get an specific spreadsheet value from the rows object? And could we modify that element of the rows object? Is the rows object an array? Could we modify an entry by setting rows[int][int]="value"? I'm really a noob student trying to finish a project and do not have much node.js experience.
Problem bulking rows
Hello @jpillora,
I try to bulk local data to a Google Spreadsheet using your module but I get the next error:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:batch="http://schemas.google.com/gdata/batch">
<id>http://spreadsheets.google.com/feeds/cells/txCtIc0YbAB1UOSSzgB8dxA/od7/batch/1374829438594</id>
<updated>2013-07-26T09:04:00.206Z</updated>
<title>Batch Feed</title>
<entry>
<id>http://spreadsheets.google.com/feeds/cells/txCtIc0YbAB1UOSSzgB8dxA/od7/private/full/R1C1</id>
<updated>2013-07-26T09:04:00.206Z</updated>
<title>Error</title>
<content>We're sorry, a server error occurred. Please wait a bit and try reloading your spreadsheet.</content>
<batch:id>UpdateR1C1</batch:id>
<batch:status code="403" reason="We're sorry, a server error occurred. Please wait a bit and try reloading your spreadsheet."/>
<batch:operation type="update"/>
</entry>
<entry>
<id>http://spreadsheets.google.com/feeds/cells/txCtIc0YbAB1UOSSzgB8dxA/od7/batch/1374829438594/fatal</id>
<updated>2013-07-26T09:04:00.208Z</updated>
<title>Fatal Error</title>
<content>Feed processing was interrupted.</content>
<batch:interrupted reason="a response has already been sent for batch operation update id='UpdateR1C1'" parsed="3000" success="0" error="1" unprocessed="2999"/>
</entry>
</feed>
I've debugged and I found the problem is the spreadsheet rows size, so that if I increase manually the page, the bulk works.
Does exist any way to increase the pagesize automatically? I think this is important because the default size is 60 rows, I think this module haven't sense if you can't bulk more than those rows.
Thanks!!
API hangs forever when retrieving a sheet.
Just noticed this behavior. The requests seem flaky. Some go through and I am able to retrieve the sheet, some don't and it gets stuck at the "Searching for Worksheet ...".
Saw a related post on SO for the same:
https://stackoverflow.com/questions/31708602/spreadsheet-api-hangs-forever?newreg=ff9c1d4320ef4df88674e021a0b13fc2
Expiring token
Hi,
I'm using oauth with a key stored in PEM to do server-side login with edit-google-spreadsheets. It looks like that after some time of inactivity, if the program try to read information again, then gets a 401 error Token invalid - Invalid token: Token not found
.
When I had moderate traffic (double digits writes to the spreadsheet / hour) then there didn't seem to be any problem. This came out when I had a low traffic (one event ever few hours).
Now I try to periodically run some commands to the server (a spreadsheet.receive()
), with a period of 15 minutes, still got the token expiry problem. Testing with "every 5 minutes" interaction to see if that fixes is. Any other way to keep the token valid without manually re-login on such an error?
Thanks!
Possible to create new tabs?
When I try to use another tab name, I had been hoping that it would be created. Perhaps a bit silly of me. Is there a way to create new tabs with the APIt at the moment?
Looking for maintainers!
Hi guys, I haven't used this project myself for quite sometime and I'm very short for time these days. Would someone like to volunteer?
Having trouble with massive adding rows
Hi,
I really like your module, it's really useful and well written.
I use it to write random datas into a spreadsheet, and then use d3 to parse that spreadsheet. So it's a lot of time saves thanks to it.
But I'm having some trouble when I try to add multiple rows at the same time.
For example if I want to add 50 rows, it works twice and then I get an error message.
Does it have a way to add multiple rows in a massive way ?
Thx.
Create unit tests
Ideas
- within the current account (requires a
creds.json
), uses google-drive to create a temporary spreadsheet, run tests on this spreadsheet, then deletes it - preferably use mocha
Getting error on 'Invalid integer format'
When I try to upload an array with key-value attributes (all should be strings) - I get this error:
Response:
https://spreadsheets.google.com/feeds/cells/toYKA6TAZ2e-MZlZbY-gBYg/od6/batch/1376565179637
2013-08-15T11:12:59.642Z
Spreadsheet Size
Hi again,
It's now over a week I'm getting used to this library and most of my script is using automated flow and at the initialization of a document I'm having a small problem.
When the script run, let's say I have 50 columns to send, but the document has only 30 columns. I'm getting errors in this case regarding cell_id does not exist, which is a correct warning.
I can manually add columns and cells into the Sheet, but it could be a cool feature if this library could auto-expand the sheet so that my 'updates' could fit into the sheet.
Obtaining calculated values from cells
Is there a way to obtain calculated values from cells? I have a formula in a spreadsheet and I would like to get the result of the formula and not the formula string itself.
Could an option be added to obtain the value of cells with formulas?
https://github.com/jpillora/node-edit-google-spreadsheet/blob/stable/lib/util.js#L19-L32
Major bug in send() method
I've found a bug in the method flow. I've fixed it but I don't able to create the pull request correctly, so here you have the fix: IvanGuardado@5e42264
Release as soon as posible!
Problem with leading zero
I'm having problems with leading zeros getting removed from data in the spreadsheet. I have formatted the spreadsheet to plain text and also making sure the data that I send is a string. Am I missing something?
Spreadsheet.prototype.send should check response.statusCode
If response.statusCode != 200 and body doesn't include "success='0'"
(which, for example, occurs if your token has expired), no error is reported.
Can't read metadata
Looks like the url to get the feed didn't get updated in metadata.js (updated in index.js), also the metadata object from Google now has different property names for updated, title, rowCount, and colCount.
These prevents successful updates to Google Spreadsheet using the module for me:
Logging into Google...
Logged into Google
Sending updates...
Determining worksheet size...
TypeError: Cannot read property 'updated' of undefined
at Metadata.extract (/Users/ken/Projects/institution-webapp/scripts/node/localization/node_modules/edit-google-spreadsheet/lib/metadata.js:15:35)
at /Users/ken/Projects/institution-webapp/scripts/node/localization/node_modules/edit-google-spreadsheet/lib/metadata.js:28:26
at Request._callback (/Users/ken/Projects/institution-webapp/scripts/node/localization/node_modules/edit-google-spreadsheet/lib/index.js:125:12)
at Request.self.callback (/Users/ken/Projects/institution-webapp/scripts/node/localization/node_modules/edit-google-spreadsheet/node_modules/request/index.js:148:22)
at Request.emit (events.js:98:17)
at Request. (/Users/ken/Projects/institution-webapp/scripts/node/localization/node_modules/edit-google-spreadsheet/node_modules/request/index.js:876:14)
at Request.emit (events.js:117:20)
at IncomingMessage. (/Users/ken/Projects/institution-webapp/scripts/node/localization/node_modules/edit-google-spreadsheet/node_modules/request/index.js:827:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:938:16
=concatenate(S2,T2,U2) instead of actual value
After getting the spreadsheet from google instead of getting the actual text visible in the cell I'm getting the action that is used to produce its content. Is there a way to receive just the text?
{ '1': 1,
'2': 'name',
'3': '=CONCATENATE("new item ",B2," & ",C2)',
'4': 00000012,
'5': '=CONCATENATE(A2,"_",G2,"_",H2,"_",I2,"_",J2)',
'6': 1,
'7': '=concatenate(S2,T2,U2)',
...
}
``
Characters being replaced/lost
If I have a cell that looks like this: "Peanut Butter & Jelly", the results from this package will be returned as "Peanut Butter&Jelly". I can live with the character code replacement, but it is also removing spaces. Additionally, I've noticed that newlines are also removed, so something like:
"Hello
World"
becomes "HelloWorld".
I looked in the code, and noticed if I change the gcell2cell function in utils.js to return cell.inputValue as opposed to exports.num(cell.$t), it works as expected, although this probably causes issues with numeric cells.
Master branch is unstable
I've cloned your respository and I've realized that the code in master is very different to the code I had installed with npm. In fact, I try to launch the example scripts and a lot of errors occur: require files that doesn' exist, use undefined vars, etc...
WTH? I don't know where I have to start to work. Tag 1.0 seems to be right, however I feel you are working in a code refactoring.
Could you help me? Thanks!
After error, stops to write
Hi,
if i try to write a row on a document without free row I receive the following error:
- Error updating spreadsheet: [400] the value of the query parameter cell_id is not valid
after this error the lib stops to write on all other spreadsheet until the next restart
Error installing npm
When I try to install the npm with npm install edit-google-spreadsheet
in my root directory I get this error. I am using Windows 8.1 and Atom to write the code.Has anyone else had this problem and found a solution?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.