Use this together with GetGoogleSpreadsheet from the File Exchange and you can read/write to Google Sheets from MATLAB. Inspired by an older set of functions (Matlab to Google Spreadsheets) that no longer works with Google's new v4 API.
status = mat2sheets(spreadsheetID, sheetID, sheetpos, d)
% This function takes values from an array or cell array and places them in
% a Google spreadsheet. It requires the one-time use of RunOnce (see below)
% SYNTAX: status = mat2sheets(spreadsheetID, sheetID, pos, d)
% spreadsheetID: (string), identifier from URL of your Google Sheet
% sheetID: (string), another identier from URL
% pos: 1x2 array with indices for [sheetrow, sheetcolumn]
% to start pasting data
% d: array or cell array of data to paste into Sheet. If
% , pos indicates row or range of rows [start stop]
% to delete
% RETURNS: status (0=failed, 1=success)
% For sheet with the following URL:
% A call may look like:
% mat2sheets('1GPd-vBsX5VUejz5hrxE', '552', [2 3], [1 2 3 4 5])
% Would put values 1,2,3,4,5 into cells C2,D2,E2,F2,G2, respectively
% To delete row(s)
% mat2sheets('1GPd-vBsX5VUejz5hrxE', '552', 2, ) % delete row 2
% mat2sheets('1GPd-vBsX5VUejz5hrxE', '552', [2 10], ) % delete rows 2-10 inclusive
% USING RunOnce().
% Before using this code, you've got to enable the Drive/Sheets APIs via:
% Here, you will "create credentials" via an OAuth 2.0 client ID that comes
% with a Client ID and Client Secret. These codes are the two arguments of
% RunOnce(client_id, client_secret). Run RunOnce with both of these
% codes passed as strings, and follow the instructions.
% The following code is inspired by, and makes use of, code
% originally published in the file exchange by Claudiu Giurumescu.
% I wrote this to accomodate for latest changes in Google API, added some
% comments, and simplified it all so that it can be implemented by the
% average user (hopefully!)
% Additionally, I use loadjson by Qianqian Fang to read the input streams
% from Google for learning meta data about the sheets
% andrew robert bogaard 26 sept 2016
% updated 25 july 2017 (delete rows)
Andrew Bogaard (2022). Matlab to Google Sheets (matlab2sheets) (https://github.com/abogaard/matlab2gsheets), GitHub. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!