View License

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

» Watch video

Highlights from
Matlab to Google Spreadsheets

4.8 | 12 ratings Rate this file 8 Downloads (last 30 days) File Size: 22 KB File ID: #31221 Version: 1.3

Matlab to Google Spreadsheets



27 Apr 2011 (Updated )

Matlab functions to send data to Google Spreadsheets.

| Watch this File

File Information

WARNING: This code does not work anymore with the current Google Sheets API. Please use the Matlab2Sheets project below.
This set of Matlab functions will allow creating Google
spreadsheets, adding worksheets to them, modifying the
worksheets, and placing data in them.


Create Google Calendar Event With Sms And Email Notification and 41 Complete Gui Examples inspired this file.

This file inspired View And Add Transaction To Portfolios On Google Finance and Matlab To Google Sheets (Matlab2sheets).

MATLAB release MATLAB 8.5 (R2015a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (22)
07 Nov 2016 Paolo Bocchini

These scripts worked great for a long time, but now I keep getting error "Last response was: 404/Not Found" even if I try just Matlab2GoogTest

14 Oct 2016 valarmathi I

I am getting "Last response (POST) was: 403/Forbidden", though I have entered my cliend id and secret, and also given the permissions for OAuth2. Are there other permissions Im missing?

Comment only
06 Jul 2016 Finlay MacLean

I've been playing around with it for a while, and can't get passed "Error using urlreadwrite
Too many input arguments."
Can anyone point me in the right direction?

Comment only
10 Oct 2015 Matthias

Looks cool, but the Matlab2GoogTest.m script does not work for me. After fixing some errors, I got it to upload files to google, but the spread sheets always arrive empty except for the A1 cell, which contains a string like "[B@74727a7d" or similar. What could be the problem? Thanks!

Comment only
05 Sep 2015 Scott

Scott (view profile)

Here is the code to update an entire row with one batch update:
function editWorksheetRow(spreadSheetKey,workSheetKey,row,columnNumbers,cellValues,aToken)

import java.lang.*;


nCols = 15;
while (~success && safeguard<MAXITER)
nEntries = length(columnNumbers);

% Get edit details
urlCell=['' spreadSheetKey '/' workSheetKey '/private/full?return-empty=true&min-row=' num2str(row) '&max-row=' num2str(row) '&min-col=1&max-col=' num2str(nCols)];
con = urlreadwrite(mfilename,urlCell);
con.setRequestMethod( 'GET' );
con.setDoInput( true );
con.setRequestProperty('Authorization',['Bearer ' aToken]);
if (con.getResponseCode()~=200)

con.disconnect(); clear con;

con = urlreadwrite(mfilename,getURLStringList);
con.setDoOutput( true );
con.setRequestProperty('Authorization',['Bearer ' aToken]);

event = '';
event=['<feed xmlns='''' ' ...
'xmlns:batch='''' ' ...
'xmlns:gs=''''>' ...
for i=1:nEntries
slashIdx = strfind(editKey,'/');

event = [event '<entry>' ...
'<batch:operation type=''update''/>'...
'<link rel=''edit'' type=''application/atom+xml'' '...
strcat(' href=''',spreadSheetKey,'/',workSheetKey,'/private/full/R',num2str(row),'C',num2str(columnNumbers(i)),'/',editKey,'''/>')...
strcat('<gs:cell row=''',num2str(row),''' col=''',num2str(columnNumbers(i)),''' inputValue=''',cellValues{i},'''/>')...
event = [event '</feed>'];
ps = PrintStream(con.getOutputStream());
ps.close(); clear ps;
if (con.getResponseCode()~=200)
if success
con.disconnect(); clear con;
display(['Last response was: ' num2str(con.getResponseCode) '/' con.getResponseMessage().toCharArray()']);
clear con;

Comment only
01 Sep 2015 Scott

Scott (view profile)

Never mind on my earlier post - I just needed to enable the drive API and the permission error disappeared. Everything works great now. Thank you!

01 Sep 2015 Scott

Scott (view profile)

I am getting "Last response (POST) was: 403/Forbidden", though I have entered my cliend id and secret, and also given the permissions for OAuth2. Are there other permissions Im missing?

03 Jul 2015 Paolo Bocchini

Same here: it used to work perfectly, and it is so well done! Unfortunately it recently stopped working and I keep getting "Could not obtain authorization tokens from Google."
Something must have changed in Google's API. If anyone finds a fix, please post it.

12 Oct 2014 Kristjan Poder

Has worked brilliantly until recently, when can not obtain tokens from Google any more. Is there a fix of any nature?

23 Apr 2014 Kent Conover

Great idea, but "MatlabGoogTest" returns "Could not obtain authorization tokens from Google." when I try to log in. I am eager to see a fix!

Comment only
11 Oct 2013 Sven

Sven (view profile)

Wonderful work. The two things stopping 5 stars at the moment is documentation (none of the functions that the user must call have any help contents) and the 1-cell-at-a-time functionality only.

It would be very advantageous to supply similar functionality to xlsread/xlswrite, which both accept a cell range to read/write, and if no range is given, xlsread simply returns the full contents of that worksheet.

09 Apr 2013 Malte Ahm

Really great functions! what is missing for me is a "editWorksheetCellBatch" function to be able to edit larger worksheets quicker.

I can see, that the Google API should support it:

I have tried making the function myself, but my experience with java and html protocols is very limited. I keep getting an error 400 (Bad Request) when i try to send the data to the server (ps.print(event)).

08 Apr 2013 Thomas

Thomas (view profile)

How long is the authentication valid for? I'm running this in a loop and I start getting 403 errors after about 500 seconds, which doesn't happen if I run each iteration by itself

Comment only
08 Apr 2013 Thomas

Thomas (view profile)

08 Apr 2013 Thomas

Thomas (view profile)

Works great!

12 Nov 2012 Eric Trautmann

Eric Trautmann (view profile)

26 Apr 2012 Claudiu Giurumescu


The code below should work (replace connectNAuthorize function in the package with the one below)
urlread should be provided by Matlab.

The 'writely' token is for Google Spreadsheets, the 'wise' token is for Google Docs.

Once you have the tokens you can use the other functions in the package.

Hope this helps,

[authorized, aTokenS]=connectNAuthorize(userName, password,'writely');
if (~authorized)
[authorized, aToken]=connectNAuthorize(userName, password,'wise');
if (~authorized)

function [authorized, aToken]=connectNAuthorize(userName, password,service)


if authorized==1
aToken=['auth' str(strfind(str,'Auth')+4:end-1)];

Comment only
26 Apr 2012 Matt Behr

hello .... is there anyway to avoid the credentials dialog. I want to run a script nightly to update data in google docs.


Comment only
11 Feb 2012 ted p teng

ted p teng (view profile)

Excellent toolbox! You can also easily modify the 'editWorksheetCell' to edit for an array of cells instead of individual cells for reducing the number of http requests [ ].

24 Jun 2011 Jake Hughey

20 Jun 2011 Claudiu Giurumescu


Thanks for the suggestion. I've updated the submission. You can now read both the cell value and its formula.

Hope this helps.

Comment only
18 Jun 2011 Jake Hughey

this set of functions looks great, but what is missing for me is a "getWorksheetCell" function, because I also want to pull data from google spreadsheets into matlab. I don't know java well enough to write one myself.

Comment only
20 Jun 2011 1.1

Google login process has dialog box. New function reads values and formulas from the Google spreadsheet.

25 Aug 2015 1.2

Updated to Google OAuth2

06 Sep 2015 1.3

added two new functions

23 Dec 2016 1.3

mention about new Google API

Contact us