How can DropDown Items dynamically obtain the name of different sheets in Excel instead of manually entering items?

1 次查看(过去 30 天)
If the items of dropdown are the names of multiple sheets of Excel, how to write the callback function is that the items are not written in by themselves, but obtained by importing Excel to read different sheets,Who can help me solve this problem, write a callback function or send a template?

采纳的回答

Simon Chan
Simon Chan 2022-3-27
When you import the file, get the sheet names and put them as the 'Items' of the uidropdown.
sheetName = sheetnames(fullfile(pathname,filename));
% dd = uidropdown(uif,'Items',{''},'Value',{''}); % Assume original is empty
set(dd,'Items',sheetName,'Value',sheetName(1))
  3 个评论
Simon Chan
Simon Chan 2022-3-28
Suppose your data in the excel sheets are all numeric data, you can use function readmatrix:
%uit = uitable(uif) % Don't know your uitable configuration
uit.Data = readmatrix(fullfile(pathname,filename),'Sheet',dd.Value); % Read the sheet choosen from the uidropdown

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by