Main Content

xlsfinfo

(Not recommended) Determine if file contains Microsoft Excel spreadsheet

xlsfinfo is not recommended. Use sheetnames instead. For more information, see Compatibility Considerations.

Description

status = xlsfinfo(filename) indicates if filename is a file that the xlsread function can read.

[status,sheets] = xlsfinfo(filename) additionally returns the name of each spreadsheet in the file.

example

[status,sheets,xlFormat] = xlsfinfo(filename) also returns the format description that Excel® returns for the file. On systems without Excel for Windows®, xlFormat is an empty character vector, ''.

Examples

collapse all

Create a sample Excel® file named myExample.xlsx.

values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First', 'Second', 'Third'};
xlswrite('myExample.xlsx', [headers; values]);

Call xlsfinfo to get information about the file.

[status,sheets,xlFormat] = xlsfinfo('myExample.xlsx')
status =

Microsoft Excel Spreadsheet


sheets = 

    'Sheet1'    'Sheet2'    'Sheet3'


xlFormat =

xlOpenXMLWorkbook

status contains descriptive text which indicates that the xlsread function can read the sample file.

Input Arguments

collapse all

Name of file, specified as a character vector or a string.

Example: 'myFile.xlsx'

Data Types: char | string

Output Arguments

collapse all

Type of file, returned as a character vector.

  • If filename is a file that xlsread can read, then status is descriptive text, such as 'Microsoft Excel Spreadsheet'.

  • If filename is not a file that xlsread can read, then status is empty, ''.

  • If MATLAB® cannot find the file, then xlsfinfo returns an error.

Worksheet names, returned as a 1-by-n cell array of character vectors, where n is the number of worksheets in the file. Each cell contains the name of a worksheet. If xlsread cannot read a particular worksheet, the corresponding cell contains an error message.

If xlsfinfo cannot read the file, then sheets contains an error message.

File format description returned by Excel, returned as a character vector.

On Windows systems with Excel software, xlFormat is one of the following.

'xlOpenXMLWorkbook'Spreadsheet in XLSX format (Excel 2007 or later)
'xlWorkbookNormal' or 'xlExcel8'Spreadsheet in XLS format (compatible with Excel 97-2003)
'xlCSV'File in comma-separated value (CSV) format
'xlHtml' or 'xlWebArchive'Spreadsheet exported to HTML format

On all other systems, xlFormat is an empty character vector, ''.

Limitations

  • xlsfinfo supports only 7-bit ASCII characters.

Tips

  • If xlsfinfo warns that it cannot start an ActiveX® server, then the COM server, which is part of the typical Excel installation, is unavailable. In this case, consider reinstalling your Excel software. On systems with Excel for Windows, xlsfinfo uses the COM server to obtain information.

Version History

Introduced before R2006a

collapse all

R2019b: xlsfinfo is not recommended

xlsfinfo is not recommended. Use sheetnames instead. There are no plans to remove xlsfinfo.

Starting in R2019b, use the sheetnames function to get names of worksheets from a spreadsheet file. The sheetnames function has these advantages over the xlsfinfo function:

  • Support for sheet names containing non-ASCII characters

  • Better cross-platform support and performance

  • Ability to work with remotely stored data

This table shows typical usages of xlsfinfo and how to update your code to use sheetnames.

Not Recommended

Recommended

[~,sheets] = xlsfinfo('myData.xls')
sheets = sheetnames('myData.xls')