xlsread

Reads data, which is an Excel-compatible file or a structure returned from xlsopen. This command is only available on Windows at this time.

Syntax

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

[num, txt, raw] = xlsread(data, wsheet,...)

[num, txt, raw] = xlsread(data, range,...)

[num, txt, raw] = xlsread(data, wsheet, range,...)

[num, txt, raw] = xlsread(data, wsheet, range, 'interface', itype)

Inputs

data
Name of the file to read or a structure returned as the result of an xlsopen. If data is a filename, the file extension must be Excel compatible. If data is a structure, xlsclose must be called after all the xlsread operations are complete.
Type: string | struct
wsheet (optional)
Specifies the worksheet name or number. The default worksheet read is the first one if no argument is specified. If only two arguments are used and the second string argument does not contain a ':', it is considered to be the worksheet name.
Type: int | string
range (optional)
Specifies the range where the data needs to read from. Range should be in an Excel-compatible format, with a ':'.
Type: string
itype
Interface type for xlsread. Valid values are oml(default) and com. com interface runs the Qt/ActiveX COM libraries, which require Microsoft Excel to be installed on the machine.
Type: string

Outputs

num
Matrix containing numeric real data. Strings in file are stored as 'NaN'. The dimensions of the matrix are the same as the dimensions of the data that is read.
Type: matrix
txt
Cell array containing string data. Numeric data in file is stored as empty strings. The dimensions of the cell are the same as the dimensions of the data that is read.
Type: cell
raw
Cell array containing all data. The dimensions of the cell ate the same as the dimensions of the data that is read.
Type: cell

Examples

Read an Excel file with defaults:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
xlswrite('test.xlsx', [headers; values]);
mat = xlsread('test.xlsx')
mat = [Matrix] 4 x 3
        NaN          NaN           NaN
1.00000e+00  2.00000e+00   3.00000e+00
        NaN          NaN           NaN
        NaN          NaN  1.79769e+308
Read an Excel file with worksheet number specified, using the 'com' interface:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
xlswrite('test.xls', [headers; values], 2);
mat = xlsread('test.xlsx', 2, 'interface', 'com')
mat = [Matrix] 4 x 3
        NaN          NaN           NaN
1.00000e+00  2.00000e+00   3.00000e+00
        NaN          NaN           NaN
        NaN          NaN  1.79769e+308
Read an Excel file with worksheet name, range, and all outputs specified:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
xlswrite('test.xls', [headers; values], 2);
[mat, txt, raw] = xlsread('test.xlsx', 'Sheet2', 'A2:C3')
mat = [Matrix] 2 x 3
  1    2    3
NaN  NaN  NaN
txt =
{
[1,1]
[1,2]
[1,3]
[2,1] a
[2,2] b
[2,3] c
}
raw =
{
[1,1] 1
[1,2] 2
[1,3] 3
[2,1] a
[2,2] b
[2,3] c
}
Read an Excel file with defaults using structure returned from xlsopen:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
xlswrite('test.xlsx', [headers; values], 'sheet1');
xlswrite('test.xlsx', {100, 200, 300}, 'sheet2');

data = xlsopen('test.xlsx');
mat1 = xlsread(data, 'sheet1')
mat2 = xlsread(data, 'sheet2')
xlsclose(data);
mat1 = [Matrix] 4 x 3
        NaN          NaN           NaN
1.00000e+00  2.00000e+00   3.00000e+00
        NaN          NaN           NaN
        NaN          NaN  1.79769e+308
mat2 = [Matrix] 1 x 3
        100  200  300