How to check existence of worksheet in excel file

I'm working on some script and i need to check if there's any particular name of worksheet. Is there anyway to check the workshee existing in excel file? Additionally, I wanna know if there is the way deleting particular worksheet. And I don't wanna use activeX for this. Can anybody help me?

 採用された回答

C.J. Harris
C.J. Harris 2012 年 1 月 11 日

4 投票

[A,B] = xlsfinfo('foofoo.xlsx');
sheetValid = any(strcmp(B, 'foo2'));

2 件のコメント

YoungKwang
YoungKwang 2012 年 1 月 12 日
Oh. Appreciate your answer so much. It did work. !!
Ilya Gurin
Ilya Gurin 2021 年 8 月 13 日
Matlab help now says, "xlsfinfo is not recommended. Use sheetnames instead."

サインインしてコメントする。

その他の回答 (1 件)

Doug Hull
Doug Hull 2012 年 1 月 11 日

0 投票

>> [a,b] = xlsread('foofoo.xlsx','foo2')
Error using xlsread>activate_sheet (line 435)
Specified worksheet was not found.
Error in xlsread (line 259)
activate_sheet(Excel,sheet);
Throw a Try Catch around it.

3 件のコメント

YoungKwang
YoungKwang 2012 年 1 月 11 日
Hi, Doug Hull. Thanks for relply. I got it and got to until that error massage in case there's no worksheet mentioned. But Only with this error massage, I can't seem to find the way using this manner. I need return value so that I can put this in my script.
Or am I doing wrong?
In this way, when there's no worksheet, script will stop running.
Doug Hull
Doug Hull 2012 年 1 月 11 日
I like Chris' answer better about xlsinfo. Mine will error for the wrong sheet and then you can TRY CATCH the error.
YoungKwang
YoungKwang 2012 年 1 月 12 日
I got it solved with Chris's way. But thanks for your answer as well.

サインインしてコメントする。

質問済み:

2012 年 1 月 11 日

コメント済み:

2021 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by