MATLAB Answers

Create table from excel spreadsheet with multiple sheets

313 views (last 30 days)
alpedhuez
alpedhuez on 7 Jul 2018
Commented: dpb on 7 Jul 2018
Suppose I have xlsx file with multiple sheets. I want to create table A from the first sheet and create table B from the second sheet. Please advise.

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 7 Jul 2018
Try this:
folder = fileparts(which('patients.xls')) % Determine where demo folder is.
fullFileName = fullfile(folder, 'patients.xls');
[status, sheetNames] = xlsfinfo(fullFileName)
numSheets = length(sheetNames)
t1 = readtable(fullFileName, 'Sheet', 1)
t2 = readtable(fullFileName, 'Sheet', 2)
and so on. Put in a loop if you want.

More Answers (1)

dpb
dpb on 7 Jul 2018
See
doc readtable

  2 Comments

alpedhuez
alpedhuez on 7 Jul 2018
Is it like
readtable('patients.xls',...
'Sheet',1,...)
?
dpb
dpb on 7 Jul 2018
That's certainly possible, yes...you're missing a LHS variable to assign the result to, however.

Sign in to comment.

Sign in to answer this question.

Products