Open/Edit docs stored on Microsoft Teams
21 ビュー (過去 30 日間)
古いコメントを表示
I am trying to use matlab (2024a) to open (and eventually edit) an excel doc that is stored in Microsoft teams. I am getting a 403 Forbidden response. Our IT department is stumped, as I am entering the correct credentials when prompted. Anyone been able to get around this?
Here is my code:
% Prompt for username and password
prompt = {'Enter your username:', 'Enter your password:'};
dlgtitle = 'SharePoint Login';
dims = [1 35];
definput = {'', ''};
answer = inputdlg(prompt, dlgtitle, dims, definput);
% Extract username and password
username = answer{1};
password = answer{2};
% URL for the SharePoint file
url = 'https://indiana.sharepoint.com/sites/msteams_c777c3-DistVRT/_api/web/GetFileByServerRelativeUrl(''/sites/msteams_c777c3-DistVRT/Shared%20Documents/DistVRT/DistVRT_v4_SF_DataScoringLog.xlsx'')/$value';
% Web options with the provided credentials
options = weboptions('Username', username, 'Password', password, 'Timeout', 60);
% Read the file from SharePoint
data = webread(url, options);
data = readtable('https://indiana.sharepoint.com/sites/msteams_c777c3-DistVRT/Shared%20Documents/DistVRT/DistVRT_v4_SF_DataScoringLog.xlsx','ReadVariableNames',1); %calls in text file of data for this subject
回答 (1 件)
Yash
2025 年 1 月 19 日
If your use case allows it, I highly recommend bypassing authentication to perform read/write operations directly within the SharePoint directory. Instead sync the SharePoint directory and use file I/O. You can achieve this by clicking the Sync button to access the files on your local machine.

If the above option is not feasible, go through the below resources for interacting with SharePoint using MATLAB:
While Microsoft still supports SharePoint REST API v1, the API is limited and struggles when downloading/uploading large files. For this reason you can use Microsoft Graph. The Microsoft Graph API supports partial file reads (i.e. reading a file on a specific byte range) to allow for large downloads and generating file upload sessions to handle large uploads (e.g. such as large videos).
For authentication, I recommend that you look into Microsoft's documentation on following the OAuth2 flow to generate an access token for their API, which should work for both the SharePoint REST API v1 and the Microsoft Graph API: https://learn.microsoft.com/en-us/graph/auth-v2-user?tabs=http
1 件のコメント
Yash
2025 年 1 月 19 日
Refer to this blog post for further reading: https://blogs.mathworks.com/videos/2023/05/26/using-the-sharepoint-restful-api-to-delete-past-versions-of-a-file/
Since OneDrive and SharePoint share similarities, you might also find this helpful: https://rclone.org/onedrive/#creating-client-id-for-onedrive-business
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!