xlsread

Reads numbers and text from an Excel spreadsheet.

Category: Data Import and Analysis > Data Import and Export

Syntax

num = xlsread(filename)

Reads the numeric data of the first sheet.

num = xlsread(filename, sheet)

Reads a sheet given by number or name.

num = xlsread(filename, sheet, range)

Reads only the cells of range, such as 'B2:C3'.

[num, txt, raw] = xlsread(___)

Also returns the text cells and the unprocessed contents.

Description

xlsread splits a sheet into its numeric part and its text part. A header row of labels followed by numbers gives a num without the header, and txt with the labels. Use raw when you need both kinds in their original positions.

The function is kept for older code. readmatrix, readcell and readtable are the recommended replacements, with more control over ranges and types.

Input arguments

filename
Spreadsheet file name.
sheet
Sheet index or name.
range
Cell range in A1 notation.

Output arguments

num
Numeric matrix. Cells without a number become NaN, and leading text rows or columns are trimmed away.
txt
Cell array holding the text cells; numeric cells appear as empty text.
raw
Cell array with every cell exactly as read, numbers and text together.

Examples

Header text and numbers

xlswrite('read_demo.xlsx', {'name','val'; 'a',1; 'b',2});
[num, txt, raw] = xlsread('read_demo.xlsx')
Output
num = 2×1

     1
     2
txt = 3×2 cell

    {'name'}    {'val'   }
    {'a'   }    {0×0 char}
    {'b'   }    {0×0 char}
raw = 3×2 cell

    {'name'}    {'val'}
    {'a'   }    {[  1]}
    {'b'   }    {[  2]}

A range of a sheet

xlswrite('range_demo.xlsx', magic(4));
xlsread('range_demo.xlsx', 1, 'B2:C3')
Output
ans = 2×2

    11    10
     7     6

See also

xlswrite xlsfinfo readmatrix readcell readtable