2020a readtable error when specifying rectangular range
Mostrar comentarios más antiguos
I am trying to read a .xlsx file with readtable specifying a rectangular range. I get the error shown below. I have tried reading other .xlsx files with the same result. When I do not specificy the rectangular range or when I specify only the starting cell it reads the .xlsx file OK.
ChTableXLS is a string with a path to the .xlsx file
Below is a screen shot of the .xlsx sheet I am trying to read. It is an example of a longer file - only 200 rows.

Is this a known bug in 2020a readtable? I did not find it in the bug list.
I know I can read the full sheet in and only keep what I need as a work around, but the options should work. Perhaps I am doing something wrong? I don't see anything wrong in the .xlsx files I tried.
Thank you
dat = readtable(ChTableXLS,'Sheet','Sheet3','Range','C1:F4','PreserveVariableNames',true);
Error using readtable (line 198)
First input must be either a character vector or a string scalar.
Respuesta aceptada
Más respuestas (2)
dpb
el 8 de Jun. de 2022
The error isn't anything to do with the 'Range' argument; it's the file name ("First input must...")
"ChTableXLS is a string with a path to the .xlsx file"
It's almost guaranteed to be a cellstr variable, then. While this is an annoyance and I fail to see why TMW doesn't expand the input parsing to handle it, the input file name must either be the dereference cellstr variable content or a string variable, NOT a cellstr() variable.
dat = readtable(ChTableXLS{:},'Sheet','Sheet3','Range','C1:F4','PreserveVariableNames',true);
or
dat = readtable(string(ChTableXLS),'Sheet','Sheet3','Range','C1:F4','PreserveVariableNames',true);
will either work, I'll betcha'....
1 comentario
VB ABQ
el 8 de Jun. de 2022
VB ABQ
el 8 de Jun. de 2022
1 comentario
dpb
el 8 de Jun. de 2022
I've never experienced such a situation -- looks like the error message may need some fixup to reflect the actual problem.
To debug this would need the file -- attach the .xls file using the paperclip icon.
Just for satisfying curiosity, what does
whos ChTableXLS
return?
Have you tried
dat = readtable(ChTableXLS,"Sheet","Sheet3","Range","C2:F4");
? Just to see if a string vis a vis char() makes any difference -- wouldn't expect to.
Has the range actually had anything entered in it? I rarely use ranges on reading preferring to just clean up later; when I do, it's almost always just to limit a column range rather than a preset rectangular range.
If I do have such specialized kinds of requirements I almost always end up using an import options object and any such range would end up being defined there.
But, I have used the syntax on the rare occasion and have never seen the symptom so 'tis a puzzle off top of head, yes.
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
