xlsread not able to reference my sheet names.

Good afternoon,
I've never had this problem before, I'm certain it must be a pretty easy fix.
I'm trying to open an excel file, using xlsread. I have my program on a loop though specifying that each pass it should use a sheet of a different name. It keeps telling me though that the sheet name does not exist, but when I use xlsinfo it tells me that the sheet name is there.
DATA = xlsread('DATA1', 12)
I'm just a bit stumped as to how to get around this.
Any advice would be very much appreciated!
Thanks

2 commentaires

Stephen23
Stephen23 le 6 Jan 2016
Modifié(e) : Stephen23 le 6 Jan 2016
@Chameleon17: for this forum please don't put leading space characters in front of each line of your text, because this will be formatted as monospaced text (i.e. code). I just removed your leading space characters, and you can see now how the text of your question is normal text.
I that the actual command you are using? where are you writing the filename? You also have to write the sheet name OR the number, not both

Connectez-vous pour commenter.

Réponses (2)

Image Analyst
Image Analyst le 6 Jan 2016

0 votes

Are you sure you have 12 worksheets in the workbook? Have you tried using the name of the sheet instead of it's number? Can you attach the data.xlsx workbook file to your posting with the paperclip icon?

4 commentaires

Chameleon17
Chameleon17 le 6 Jan 2016
Hi, thanks for the comments. Arg, I'm going round in circles.
DATA = xlsread('DATA1.xlsx', 12)
Data1.xlsx is the name of the excel file. There are not twelve worksheets, 12 is just the name of a sheet I would like to select. It won't even reference the first sheet though, so I don't understand what's going wrong.
If 12 is the name of the sheet rather than the number of the sheet, then you'll need to wrap it in single quotes.
[num12, strings12, raw12] = xlsread('DATA1.xlsx', '12');
I saw you just posted that this did not work. However, I'm not seeing your workbook attached anywhere so that anyone can try it. Are you able to do that? You can take out any proprietary numbers and strings if you want first.
Are you sure it's twelve and not (capital i)2?

Connectez-vous pour commenter.

Renato Agurto
Renato Agurto le 6 Jan 2016
Modifié(e) : Renato Agurto le 6 Jan 2016
The name of the sheet should be a string. You should use then:
DATA = xlsread('DATA1.xlsx', '12')
If you use a number it will select the sheet number 12 (if you have 12 sheets or more of course)

3 commentaires

Chameleon17
Chameleon17 le 6 Jan 2016
I tried that earlier and it didn't work.
What confuses me is that it tells me that it is looking for the correct name, the correct sheet, and that the xlsinfo then lists the sheet name as being there.
can you post the results of:
[status, sheets] = xlsfinfo('DATA1.xlsx')
and the error message of:
DATA = xlsread('DATA1.xlsx', '12')
After you run the above, please also post
sheets{1}, (sheets{1}+0)
so we can check for unexpected characters in the name.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by