function [m, descr] = xlsfinfo(filename)
%XLSFINFO Determine if file contains Microsoft Excel spreadsheet.
%   [A, DESCR] = XLSFINFO('FILENAME')
%
%   A is non-empty if FILENAME contains a readable Excel spreadsheet.
%
%   DESCR contains a description of the contents or an error message.
%
%   NOTE: This function does not work with the compiler.
%
%   See also XLSREAD, CSVREAD, TEXTREAD.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.9 $  $Date: 2000/06/01 04:18:03 $

% Get Filename
if ~isstr(filename), error('Filename must be a string.'); end

% do some validation
if isempty(filename), error('Filename must not be empty.'); end

% put extension on
if all(filename~='.'), filename = [filename '.xls']; end

% look for file on paht
if exist(filename,'file') ~= 2,  error(['File not found']); end

% locate file on path if name is not qualified
if isempty(fileparts(filename))
    filename = which(filename);
end

biffvector = [];

try
    biffvector = biffread(filename);
catch
    waserror = 1;
end

if ~isempty(biffvector)
    try
        m = 'Microsoft Excel Spreadsheet';
        [a,descr] = biffparse(biffvector);
        indexes = [];
        for i = 1:length(descr)
            [n,s] = biffparse(biffvector,descr{i});
            if isempty(n) & isempty(s)
                indexes(i) = logical(0);
            else
                indexes(i) = logical(1);
            end
        end
        descr = descr(indexes);
        waserror = 0;
    catch
        waserror = 1;
    end
end

if waserror | isempty(biffvector)
    m = '';
    descr = ['Unreadable XLS file: ' lasterr];
end
