Main Content


Query sheet names from datastore


names = sheetnames(ssds,filename) returns the sheet names from a specified file in the datastore ssds.


names = sheetnames(ssds,I) returns the sheet names from a specified file index.


collapse all

Create a datastore containing the file airlinesmall_subset.xlsx.

ssds = spreadsheetDatastore('airlinesmall_subset.xlsx')
ssds = 

  SpreadsheetDatastore with properties:

                      Files: {
                             ' ...\matlab\toolbox\matlab\demos\airlinesmall_subset.xlsx'
   AlternateFileSystemRoots: {}
                     Sheets: ''
                      Range: ''
            ReadFailureRule: 'error'
                MaxFailures: Inf

  Sheet Format Properties:
             NumHeaderLines: 0
          ReadVariableNames: true
              VariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more}
              VariableTypes: {'double', 'double', 'double' ... and 26 more}

  Properties that control the table returned by preview, read, readall:
      SelectedVariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more}
      SelectedVariableTypes: {'double', 'double', 'double' ... and 26 more}
                   ReadSize: 'file'

Query the sheet names of the first (and only) file in the datastore.

ans = 

  13×1 string array


Input Arguments

collapse all

Input datastore, specified as a SpreadsheetDatastore object. Use the spreadsheetDatastore function or the datastore function to create a datastore object from your data.

File in datastore, specified as a character vector or string scalar containing the name of the file to query.

The value of filename must match exactly the file name contained in the Files property of the datastore. To ensure that the file names match exactly, specify filename using ssds.Files{N} where N is the index of the file in the Files property.

Example: names = sheetnames(ssds,ssds.Files{1}) returns sheet names contained in the first file specified in the Files property of the datastore ssds.

Data Types: char | string

File index, specified as a positive integer. I cannot exceed the number of files in ssds.

Data Types: double

Output Arguments

collapse all

Sheet names, returned as a string array containing the sheet names in the specified file.

Data Types: string

Introduced in R2016a