Copy and rename Google sheet from Matlab?

조회 수: 7 (최근 30일)
Dave Erickson
Dave Erickson 2020년 11월 19일
답변: colordepth 2025년 3월 23일
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!

답변 (1개)

colordepth
colordepth 2025년 3월 23일
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.

카테고리

Help CenterFile Exchange에서 Google에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by