File Exchange

image thumbnail

GetGoogleSpreadshee​t

version 1.0 (1.97 KB) by

Download a google spreadsheet as csv and import into a Matlab cell array.

26 Downloads

Updated

View License

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).

Comments and Ratings (18)

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?

Lewis Kerwin

Where do I get parseCsv (line 36)? I do not have this function on matlab and cannot find online either.

@ mpn17

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..."

mpn17

mpn17 (view profile)

@ 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!

Yau Benor

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.

Shaun

Shaun (view profile)

This script works well, just a note that adding new lines within the sheet cells results in incorrect parsing of the sheet.

Shaun

Shaun (view profile)

Stuart McGarrity

Stuart McGarrity

Andrew Bogaard

you sir have revolutionized my labnotes

Constantine

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?

@Daniel,

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...

@Adam,

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!

~Mark

Adam Danz

Adam Danz (view profile)

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) ?

Nagavenkat

worked perfectly
Thank you

Updates

1.0

minor reformat description

1.0

update description as suggested by commenters

MATLAB Release
MATLAB 8.0 (R2012b)
Acknowledgements

Inspired: Matlab to Google Sheets (matlab2sheets)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video