Reading Excel named table doesn't work ?

20 views (last 30 days)
Mojert
Mojert on 10 Nov 2020
Edited: JE101 on 20 Jan 2021
I was trying to read an Excel named table as the documentation of readtable recomend but it doesn't seem to work.
More specificly, with the file that I provided I tried
data = readtable('test.xls', 'Range', 'table');
MATLAB tells me that the range table doesn't exist even though it does. Am I forced to hard code the range (in this case A1:B12) ?
Edit: test.xlsx is a simple spreadsheet that reproduces the behaviour. The real file I'm working on has several tables over multiple sheets that may grow in size later. So I'm interested in being able to refer to the table I'm interested in directly.
  1 Comment
JE101
JE101 on 20 Jan 2021
Edited: JE101 on 20 Jan 2021
I'd be keen to know if anyone has a fix for this too - I've run in to the same problem. As a partial workaround, you can use the old "xlsread" function. Oddly, this does recognise tables defined in Excel. The code would then be:
[numdata, textdata, celldata] = xlsread('test.xlsx', 1, 'table');
The 1 indicates that it's on the first sheet - indicating the sheet seems to be a necessary input (the code doesn't work without it).
Note that this codes doesn't seem to read in the column titles (even in the textdata or celldata) - it only reads in the data in the table.
And I've only tried this with ".xlsx" files. I don't know if it works with ".xls" files.

Sign in to comment.

Answers (1)

Stephan
Stephan on 10 Nov 2020
data = readtable('test.xlsx')
results in:
data =
11×2 table
ID Data
__ _____
1 21324
2 345
3 123
4 -984
5 485
6 3845
7 1674
8 594
9 0.38
10 924
11 947
  2 Comments
Mojert
Mojert on 10 Nov 2020
Ok, maybe I should have specified that this is a simple spreadsheet that reproduces the error but isn't the one I'm working with. The real file has multiple tables over different sheets, so I am interested in being able to specify which table to read.
Thank you for your answer nonetheless !
Stephan
Stephan on 12 Nov 2020
I can only answer on what i get fromm you. Maybe attach the file you have trouble with, will help.

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!