File Exchange

image thumbnail


version 1.0 (1.97 KB) by

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



View License

result = GetGoogleSpreadsheet(DOCID)
[DOCID] A value like '0AmQ013fj5234gSXFAWLK1REgwRW02hsd3c', which is found in your spreadsheet's url:<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 (24)

Tarun Narayan

Works like a charm!

Worked as required.

David Cagle

I am on a corporate gmail account... script will return HTML and cell array similar to what "Timothy OConnor" wrote....

I created a file on my personal gmail account and get perfect results....

Anyone know how to read data from a google file that is shared with everyone on my company account?

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?

Cedric Tsui

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?

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 = ['' 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 (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 = ['' 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 = ['' 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 (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 (view profile)

Stuart McGarrity

Stuart McGarrity

Andrew Bogaard

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:<the text here is the doc id>/edit#gid=0

Hope this helps!


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


worked perfectly
Thank you



minor reformat description


update description as suggested by commenters

MATLAB Release
MATLAB 8.0 (R2012b)

Inspired: Matlab to Google Sheets (matlab2sheets)

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

» Watch video