Copy and rename Google sheet from Matlab?

7 visualizzazioni (ultimi 30 giorni)
Dave Erickson
Dave Erickson il 19 Nov 2020
Risposto: colordepth il 23 Mar 2025
I have had great success using the mat2sheets code to write to a Google sheet directly from Matlab. I would love to be able to make a copy of the sheet and then rename it from within Matlab as well. However, I'm most definitely API-knowledge-deficient and thus far I've not had any luck with my couple of attempts using webwrite(). The Google reference here suggests the copying part is as simple as "POST https:..." and when I use their API explorer and paste in my spreadsheet ID in the "fileId" field it does indeed make a copy and returns the new file's name and new ID.
However, it's not clear to me how to execute that relatively simple command from webwrite() ? Or webread() ? Or ... something else?
Thanks for any insight!

Risposte (1)

colordepth
colordepth il 23 Mar 2025
Since you’ve successfully used mat2sheets with your client ID and secret, you already have the necessary OAuth setup. To copy and rename a Google Sheet, you’ll need to use "webwrite" to send a POST request to the Google Drive API. Start by configuring "weboptions" with your OAuth credentials, as described in this MATLAB Answer: https://www.mathworks.com/matlabcentral/answers/264403-how-can-i-access-an-api-which-requires-oauth-2-0-authorization-such-as-google-apis#answer_302103. This will help you set up the authentication for your API call.
The "webwrite" function can handle the POST request to the Google Drive API: https://www.mathworks.com/help/matlab/ref/webwrite.html.
If you prefer a more streamlined approach, MATLAB’s external language interfaces can allow you to integrate Google’s client libraries for some select programming languages, which can simplify the process. More information on this can be found here: https://www.mathworks.com/help/matlab/external-language-interfaces.html.

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by