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

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Simon Chan
Simon Chan am 27 Mär. 2022
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 Kommentare
Simon Chan
Simon Chan am 28 Mär. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by