Main Content

sheetnames

从数据存储中查询工作表名称

说明

names = sheetnames(ssds,filename) 从数据存储 ssds 中的指定文件返回工作表名称。

示例

names = sheetnames(ssds,I) 从指定的文件索引返回工作表名称。

示例

全部折叠

创建包含文件 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'

查询数据存储中第一个(且仅此一个)文件的工作表名称。

sheetnames(ssds,1)
ans = 

  13×1 string array

    "1996"
    "1997"
    "1998"
    "1999"
    "2000"
    "2001"
    "2002"
    "2003"
    "2004"
    "2005"
    "2006"
    "2007"
    "2008"

输入参数

全部折叠

输入数据存储,指定为 SpreadsheetDatastore 对象。使用 spreadsheetDatastore 函数或 datastore 函数根据您的数据创建数据存储对象。

数据存储中的文件,指定为字符向量或字符串标量,其中包含要查询的文件的名称。

filename 的值必须与数据存储的 Files 属性包含的文件名完全匹配。要确保文件名完全匹配,请使用 ssds.Files{N} 指定 filename,其中 NFiles 属性中的文件的索引。

示例: names = sheetnames(ssds,ssds.Files{1}) 返回数据存储 ssdsFiles 属性指定的第一个文件中包含的工作表名称。

数据类型: char | string

文件索引,指定为正整数。I 不能超出 ssds 中的文件数。

数据类型: double

输出参量

全部折叠

工作表名称,以字符串数组形式返回,其中包含指定文件中的工作表名称。

数据类型: string

版本历史记录

在 R2016a 中推出