Matlab to Google Sheets (matlab2sheets)
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)
%
% ARGUMENTS:
% 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)
%
% EXAMPLES:
% For sheet with the following URL:
% https://docs.google.com/spreadsheets/d/1GPd-vBsX5VUejz5hrxE/edit#gid=552
%
% 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:
% https://console.developers.google.com/
% 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.
% (https://www.mathworks.com/matlabcentral/fileexchange/31221-matlab-to-google-spreadsheets)
%
% 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
% (https://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab--a-toolbox-to-encode-decode-json-files)
%
% andrew robert bogaard 26 sept 2016
% updated 25 july 2017 (delete rows)
% abogaard@uw.edu
Zitieren als
Andrew Bogaard (2024). Matlab to Google Sheets (matlab2sheets) (https://github.com/abogaard/matlab2gsheets), GitHub. Abgerufen.
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
Tags
Quellenangaben
Inspiriert von: JSONLab: portable, robust JSON/binary-JSON encoder/decoder, GetGoogleSpreadsheet
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Versionen, die den GitHub-Standardzweig verwenden, können nicht heruntergeladen werden
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0.0 | This is a beta version, not extensively tested. Please let me know what needs fixing! :)
trivial metadata updates
% To delete row(s)
|
|