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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Simon Chan
Simon Chan el 27 de Mzo. de 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 comentarios
Simon Chan
Simon Chan el 28 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by