function [Sheets] = xlsSheets(file)
%xlsSheets  get the names of all sheets in an Excell file
%
%   This function gets all names of the sheets in an excell file and
%   exports these names
%
%   Syntax:
%   [Sheets] = xlsSheets(file)
%
%   Input:
%   file   = the name of the Excell file
%
%   Output:
%   Sheets = the list with sheets
%
%   Example
%   Untitled
%
%   See also 

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 <COMPANY>
%       Lou Verhage
%
%       <lou.verhage@deltares.nl>	
%
%       <ADDRESS>
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://OpenEarth.nl">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and 
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute 
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 06 Sep 2010
% Created with Matlab version: 7.8.0.347 (R2009a)

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $

%%

Excel = actxserver('excel.application');

try
    file = validpath(file,'.xls');
catch exception
    err = MException('MATLAB:xlsSheets:FileNotFound','xlsSheets unable to open file %s.\n%s',...
                           file,exception.message);
    throw(err);
end

Excel.DisplayAlerts = 0;

ExcelWorkbook = Excel.workbooks.Open(file,0,true);
format = ExcelWorkbook.FileFormat;
if  strcmpi(format, 'xlCurrentPlatformText') == 1
    error('MATLAB:xlsread:FileFormat', 'File %s not in Microsoft Excel Format.', file);
end

WorkSheets = Excel.sheets;

Sheets{WorkSheets.count} = '';
fid = fopen('OverviewSheets.txt','w');
for n=1:WorkSheets.count
    TargetSheet = get(WorkSheets,'item',n);    
    Sheets{n} = TargetSheet.Name;
    fprintf(fid,'%s %s\n',num2str(n),Sheets{n});
end

fclose(fid);

%close the xls sheet
ExcelWorkbook.Close(false); % close workbook without saving any changes


