result = GetGoogleSpreadsheet(DOCID)
[DOCID] A value like '0AmQ013fj5234gSXFAWLK1REgwRW02hsd3c', which is found in your spreadsheet's url: https://docs.google.com/spreadsheets/d/<here>/edit#gid=0.
[result] cell array of the the values in the spreadsheet
IMPORTANT: The spreadsheet must be shared with the "anyone with the link" option.
This has no error handling and has not been extensively tested.
Please report issues in comments below.
Thanks to @MarkTomaszewski and @Constantine for noting the updated url format (the above description has been updated to reflect this).
I made the sheet “visible to anyone” and put the 'DOCID' info as required. Unfortunately, I always get the following message: Error: Unexpected MATLAB expression. Anyone got the same issue and found a solution to it?
Timothy, you need to make the sheet visible to anyone with the link.
+1 on corp account - script appears to be returning the HTML in a 1861x1265 cell array
In response to my comment below, Matlab seems to use it's own built in browser for web related tasks. I can sign in to Google with this browser, but I still get the html when trying to download the link.
If I use web(url) to open the link manually, I can log in to Google and it then asks me where to save the link, but after choosing a location it seems to enter an infinite wait loop in the browser...
For some reason when I try this i get an HTML result of the login screen for Google. I'm logged into google in both Chrome and IE.
I can't make the sheet shareable with anyone since it's part of a corporate Google account that doesn't allow sharing to the outside world. I have no trouble downloading the link with other software (e.g. JMP) when I'm logged into Google with my default browser.
Anybody have a fix for this?
Where do I get parseCsv (line 36)? I do not have this function on matlab and cannot find online either.
Line 1 should read:
function result = GetGoogleSpreadsheet(DOCID, gid)
Line 20 should read:
csvURL = ['https://docs.google.com/spreadsheet/ccc?key=' DOCID '&output=csv&pref=2&gid=' gid];
Yau Benor's response has a mistake in the line 20 code with an erroneous space between the 2 and ampersand "...pref=2 &gid..."
@ Yau Benor, I tried your change to alter the code for multiple sheets, but had no luck.
Tried to change line 20 to the following to match up with the new URL format, but it outputs a 594x44192 array that is too big to read.
csvURL = ['https://docs.google.com/spreadsheets/d/' DOCID '/edit#gid=' gid];
Any help greatly appreciated!
To allow multiple sheets - change lines 1 and 20 in the script to:
1 function result = GetGoogleSpreadsheet(DOCID, gid)
20 csvURL = ['https://docs.google.com/spreadsheet/ccc?key=' DOCID '&output=csv&pref=2 &gid=' gid];
This would be perfect if it would support a multi-sheet spreadsheet using the "GID" in the URL.
This script works well, just a note that adding new lines within the sheet cells results in incorrect parsing of the sheet.
you sir have revolutionized my labnotes
Hi, it took me a while to figure out this very useful script for transferring info from google sheets. The 'DOCID' info in the script didn't mention getting rid of the /edit#gid=0 and spreadsheets/d stuff... what you stated explicitly in the helpful response below. If you can update the comments in the script it would be nice! Thanks!
Thanks for a great script works fine. :-) Any ideas on how to also store a hyperlink associated with a cell text, though?
Thank you very much! This works perfectly when the sheet is set up to be viewed by anyone with the link. Otherwise, the output contains a large cell array of html.
Is there any way to make this work for sheets that are set up without sharing?
Also, your description may benefit from edits according to the following...
When I access my sheet in browser I see a URL that looks like this:
https://docs.google.com/spreadsheets/d/<the text here is the doc id>/edit#gid=0
Hope this helps!
This looks incredibly useful.
Any updates now that google sheets has been merged with good drive and no longer contains the 'key=' part (replaced with /d/ but still doesn't work with this code) ?
minor reformat description
update description as suggested by commenters