Import selected row data of selected sheet in a Google sheet to MATLAB Appdesigner and populate a table (UITable)

5 次查看(过去 30 天)
I have a google spreadsheet which has four different tabs. How do i import data from each of the tabs(lets say from range A1 to A100) separately to four tables in MATLAB App Designer? I am using MATLAB 2020b.

回答(1 个)

Sandeep Mishra
Sandeep Mishra 2023-6-22
Hello Toufique,
I understand that you are trying to import data from a google spreadsheet and want to display data into 4 different tables.
In MATLAB, webread can be used to read content from any specified url.
First, you need to search for the ID in the google spreadsheet url, like below
Url = https://docs.google.com/spreadsheets/d/<spread_sheet_id>/edit#gid=0
You can implement the webread function like the below example and update the app's table based on the sheet's data.
% Google spreadhsheet ID
ID = "<spread_sheet_id>";
% Spreadsheet Sheet Name
Sheet1Name = "Sheet1";
Sheet2Name = "Sheet2";
Sheet3Name = "Sheet3";
Sheet4Name = "Sheet4";
% Fetching Sheet1 Data
Sheet1Url = sprintf('https://docs.google.com/spreadsheets/d/%s/gviz/tq?tqx=out:csv&sheet=%s',...
ID, Sheet1Name);
table1Data = webread(Sheet1Url);
% Fetching Sheet2 Data
Sheet2Url = sprintf('https://docs.google.com/spreadsheets/d/%s/gviz/tq?tqx=out:csv&sheet=%s',...
ID, Sheet2Name);
table2Data = webread(Sheet2Url);
% Fetching Sheet3 Data
Sheet3Url = sprintf('https://docs.google.com/spreadsheets/d/%s/gviz/tq?tqx=out:csv&sheet=%s',...
ID, Sheet3Name);
table3Data = webread(Sheet3Url);
% Fetching Sheet4 Data
Sheet4Url = sprintf('https://docs.google.com/spreadsheets/d/%s/gviz/tq?tqx=out:csv&sheet=%s',...
ID, Sheet4Name);
table4Data = webread(Sheet4Url);
% Setting Table data to App Designer
app.Table1.Data = table1Data;
app.Table2.Data = table2Data;
app.Table3.Data = table3Data;
app.Table4.Data = table4Data;
You can refer to the documentation below to learn more about webread.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by