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
Jie Wu
Jie Wu 2022년 3월 28일
Good job! Thank you so much. It's admirable. Your method worked again!

댓글을 달려면 로그인하십시오.

추가 답변 (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