MATLAB Function Reference    
xlsread

Read Microsoft Excel spreadsheet file (.xls)

Syntax

Description

A = xlsread('filename') returns numeric data in array A from the first sheet in Microsoft Excel spreadsheet file named filename. xlsread ignores leading rows or columns of text. However, if a cell not in a leading row or column is empty or contains text, xlsread puts a NaN in its place in A.

[A, B]= xlsread('filename') returns numeric data in array A, text data in cell array B. If the spreadsheet contains leading rows or columns of text, xlsread returns only those cells in B. If the spreadsheet contains text that is not in a row or column header, xlsread returns a cell array the same size as the original spreadsheet with text strings in the cells that correspond to text in the original spreadsheet. All cells that correspond to numeric data are empty.

[...]= xlsread('filename','sheetname') read sheet specified in sheetname. Returns an error if sheetname does not exist. To determine the names of the sheets in a spreadsheet file, use xlsfinfo.

Handling Excel Date Values

When reading date fields from Excel files, you must convert the Excel date values into MATLAB date values. Both Microsoft Excel and MATLAB represent dates as serial days elapsed from some reference date. However, Microsoft Excel uses January 1, 1900 as the reference date and MATLAB uses January 1, 0000.

For example, if your Excel file contains these date values,

use this code to convert the dates to MATLAB dates.

Examples

Example 1 - Reading Numeric Data

The Microsoft Excel spreadsheet file, testdata1.xls, contains this data:

To read this data into MATLAB, use this command:

Example 2 - Handling Text Data

The Microsoft Excel spreadsheet file, testdata2.xls, contains a mix of numeric and text data.

xlsread puts a NaN in place of the text data in the result.

Example 3 - Handling Files with Row or Column Headers

The Microsoft Excel spreadsheet file, tempdata.xls, contains two columns of numeric data with text headers for each column:

If you want to import only the numeric data, use xlsread with a single return argument. xlsread ignores a leading row or column of text in the numeric result.

To import both the numeric data and the text data, specify two return values for xlsread.

See Also

wk1read, textread, xlsfinfo


  xlsfinfo xmlread