Well this has been a journey.

All I wanted to do was to append a row to the bottom of a Google Docs Spreadsheet using Javascript.

I have looked all over for help with this but just keep drawing a blank.  Anyway it is either so easy that no one else could be bothered to write it down, or I am terminally dumb.  Either way I decided to share what I worked out.

I have set up a demo page here.  (sorry about the ssl nag...)

Work your way along the buttons from left to right.  As you go you will:

  • Log in into your Google docs account
  • Check to make sure you are logged in,  This should display your login token.
  • Debug your login, this should show you that you are logged into two scopes (one for docs, one for spreadsheets)
  • Create a Spreadsheet in your google docs account.
  • Look up that sheet (to get its unique ID) (this also adds a heading to the top of the first column)
  • Append a row to your sheet.  (you should see the time being added to the first column each time you click the button)
  • Logout to revoke the access from my webpage to your google docs account.

Just view the page source to see how it was (badly) done.

I am not claiming that this code is good, or even useful, but it does at least prove that you can insert into a Google spreadsheet with Javascript.

I offer no warranty, if this webpage crashes your dog or eats your car,  don't blame me.

If anyone is bothered and/or interested I will go thru the code line by line with some real explanations.  Leave a comment if you want me to put the time and effort in.

Update 10/01/2011.  Fixed this as Google now require https for all Doc API calls.  Makes sense really.  Because of the requirement for ssl I have updated the link ftom this post to use SSL to avoid the mixed secure and insecure content issues.