sheetnames

Lists the sheet names of a spreadsheet file.

Category: Data Import and Analysis > Data Import and Export

Syntax

names = sheetnames(filename)

Returns the names of all sheets, in file order.

Description

Use sheetnames to find out what a workbook contains before reading it, then pass one of the names as the 'Sheet' option of readmatrix, readtable or readcell.

Input arguments

filename
Spreadsheet file name, such as an .xlsx file.

Output arguments

names
String column vector with one name per sheet.

Example

Two-sheet workbook

writematrix([1 2; 3 4], 'x.xlsx', 'Sheet', 'data');
writematrix([5 6], 'x.xlsx', 'Sheet', 'more');
sheetnames('x.xlsx')
readmatrix('x.xlsx', 'Sheet', 'more')
Output
ans = 2×1 string array

    "data"
    "more"
ans = 1×2

     5     6

See also

readmatrix readtable readcell writematrix