How to access Google Sheet spreadsheets using Javascript only?

I want to access Google spreadsheets using only JavaScript. (no .NET C #, Java)

I came here and was shocked to know that there is no JavaScript for JavaScript to access the Google spreadsheet.

Please tell me how to access (CREATE / EDIT / DELETE) Google Sheets using JavaScript or any of its frameworks like jQuery etc.

+67
javascript google-api google-data-api google-sheets-api google-api-js-client
Nov 10 2018-10-11
source share
10 answers

I created a simple javascript library that retrieves google spreadsheet data (if published) via the JSON api:

https://github.com/mikeymckay/google-spreadsheet-javascript

You can see it in action here:

http://mikeymckay.github.com/google-spreadsheet-javascript/sample.html

+49
Jan 27 '11 at 17:56
source share

Gist here.

You can create a spreadsheet using the Google Sheets API . There is currently no way to delete a table using the API (see Documentation). Think of the Google Docs API as the route to create and search for documents.

You can add / remove worksheets in a spreadsheet using worksheet-based sheets .

Spreadsheet updates are performed through lists based on a list or cell-based feeds .

You can read the spreadsheet using the Google Spreadsheets APIs mentioned above, or only for published sheets, using the Google Visualization API Query Language to query data (which can return results in CSV, JSON, or HTML table format).




Forget jQuery. jQuery is really very valuable if you cross the DOM. Since GAS (Scripting) does not use the DOM, jQuery will not add any value to your code. Stick to vanilla.

I am really surprised that no one provided this information in the answer. Not only can this be done, but it is relatively easy to do using vanilla JS. The one exception is the Google Visualization API, which is relatively new (since 2011). The rendering API also works exclusively through the HTTP request string URI.

+33
Dec 29 '11 at 10:21
source share

Jan 2018 UPDATE . When I answered this question last year, I forgot to mention the third way to access the Google APIs using JavaScript, and that would be from Node.js applications using its client library, so I added it below.

It's Mar 2017 , and most of the answers here are out of date - the accepted answer now refers to a library that uses an older version of the API. More relevant answer: you can access most of the Google APIs only using JavaScript. Google offers 3 ways to do it today:

When using the REST API, you need to manage and store the source code, as well as authorize by copying your own auth code (see examples above). Script applications handle this on your behalf, managing the data (reducing the “pain” as Ape-inago mentioned in their answer ), and your code is stored on Google servers. But your functionality is limited by the capabilities provided by App Script services and older JS (ES3 + some ES5 features and Google settings), while the REST API provides developers with much wider access to the API. But hey, it's good to have a choice, isn't it? So, to answer the original OP question, instead of zero, developers have three ways to access Google Sheets using JavaScript.

+27
Mar 13 '17 at 6:55
source share

Update 2016 . The easiest way is to use the Google Apps Script API, in particular the SpreadSheet Service . This works for personal sheets, unlike other answers that require a spreadsheet to be published.

This will allow you to bind JavaScript code to a Google worksheet and execute it when you open the worksheet or when a menu item (which you can define) is selected.

Here's a quick start / demo . The code is as follows:

// Let say you have a sheet of First, Last, email and you want to return the email of the // row the user has placed the cursor on. function getActiveEmail() { var activeSheet = SpreadsheetApp.getActiveSheet(); var activeRow = .getActiveCell().getRow(); var email = activeSheet.getRange(activeRow, 3).getValue(); return email; } 

You can also publish scripts such as web applications .

+9
Feb 10 '16 at 18:43
source share

edit:. This was answered before the google doc api was released. See Evan Place's answer and Dan Daskalescu's answer for more up to date information.

Sounds like you can, but it's a pain to use. It includes the use of the Google Data API.

http://gdatatips.blogspot.com/2008/12/using-javascript-client-library-w-non.html

"The JavaScript client library has helper methods for Calendar, Contacts, Blogger, and Google Finance. However, you can use it with almost any Google data API to access authenticated / private feeds. This example uses the DocList API."

and an example of writing a gadget that interacts with spreadsheets: http://code.google.com/apis/spreadsheets/gadgets/

+6
Dec 02 '10 at 6:53
source share

“Accessing Google Docs for JavaScript will be tedious to implement, and besides that, Google documentation is not that easy either. I have good sharing links that can help you access gs for js:

http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#UploadingDocs

http://code.google.com/apis/spreadsheets/gadgets/

http://code.google.com/apis/gdata/docs/js.html

http://www.mail-archive.com/google-help-dataapi@googlegroups.com/msg01924.html

Maybe this will help you ...

+4
Dec 08 '10 at 4:45
source share

For this type you should use Google Fusion Tables . The API is designed for this purpose.

+3
Sep 30 2018-11-11T00:
source share

Sorry, this is a disgusting answer. Apparently, this has been a question for almost two years, so don't hold your breath.

Here is the official request you can "star"

Probably the closest you can come to is shuffling its own service using Google App Engine / Python and revealing everything you need with your own JS library, Although I would like for me to have a better solution.

+2
Dec 01 '10 at 22:56
source share

In this fast-paced world, most of these links are out of date.

Now you can use the Google Drive web interfaces :

+2
Dec 24 '14 at 8:43
source share

you can do this using Sheetsee.js and tabletop.js

+1
Nov 11 '16 at 9:48
source share



All Articles