View License

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

» Watch video

Highlights from

4.8 | 9 ratings Rate this file 33 Downloads (last 30 days) File Size: 1.97 KB File ID: #39915 Version: 1.0



Daniel (view profile)


18 Jan 2013 (Updated )

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

| Watch this File

File Information

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


This file inspired Matlab To Google Sheets (Matlab2sheets).

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
09 Feb 2017 Justin Epstein

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

Comment only
21 Dec 2016 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 = ['' DOCID '/edit#gid=' gid];

Any help greatly appreciated!

Comment only
07 Dec 2016 Justin Epstein

07 Dec 2016 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];

10 Nov 2016 Justin Epstein

This would be perfect if it would support a multi-sheet spreadsheet using the "GID" in the URL.

Comment only
01 Oct 2016 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.

Comment only
01 Oct 2016 Shaun

Shaun (view profile)

01 Oct 2016 Stuart McGarrity

01 Oct 2016 Stuart McGarrity

20 Sep 2016 abogaard

abogaard (view profile)

you sir have revolutionized my labnotes

24 Dec 2015 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!

Comment only
17 Dec 2015 Oyvind Tangen Odegaard

Thanks for a great script works fine. :-) Any ideas on how to also store a hyperlink associated with a cell text, though?

12 Jun 2015 Mark Tomaszewski


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!


02 Apr 2015 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) ?

Comment only
22 Jul 2013 Nagavenkat

worked perfectly
Thank you

02 Jan 2016 1.0

update description as suggested by commenters

02 Jan 2016 1.0

minor reformat description

Contact us