1

I have an Excel file which contains more than 20 sheet. I am writing a module in Matlab where I need to check if a particular worksheet say for example 'SalaryData' is present in the Excel file.

I am not able to use xlsinfo I think, this function is not available in the Matlab version I am currently using.

I intend to use actxserver to check the existence of the worksheet. What I am currently doing is something like :

SheetExist=1;
try
  sheet = get(Excel.Worksheets,'Item',sheetname);
catch
  disp('File Does not exist');
  SheetExist=0;
end

I think there is a much better and a easier way to check.

Thanks

Kiran
  • 8,034
  • 36
  • 110
  • 176

2 Answers2

2

You can use the xlsfinfo function:

[~, sheets] = xlsfinfo(filename);
ismember(sheetname,sheets);

Notice that the sheetname is case sensitive by using the ismember function! If you want case insensitivity, use a loop and strcmpi.

EDIT: just noticed your remark about xlsinfo :p Are you sure it is not available? You mention xlsinfo is not available, but the actual function is called xlsfinfo! notice the 'f' between 'xls' and 'info'

Gunther Struyf
  • 11,158
  • 2
  • 34
  • 58
  • Wonderful, I just missed an 'f' in ´xlsfinfo´. I just dropped an f word.. quiet literally.. :) Thank you – Kiran May 02 '12 at 18:11
0

Will this help?

SheetExist=1;    
Set ws = Sheets(“sheet_name”)
If ws Is Nothing Then SheetExist=0  
neohope
  • 1,822
  • 15
  • 29
  • Thanks a lot for your time. Is it VBA code ? What I am trying is very similar. I am looking at a function similar to `exist()` in matlab. – Kiran May 02 '12 at 10:03