Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

SpreadsheetDatastore

Datastore for spreadsheet files

Description

SpreadsheetDatastore objects are associated with large collections of spreadsheet files where the collection does not necessarily fit in memory. You can use the spreadsheetDatastore function or the datastore function to create a SpreadsheetDatastore object. Once the object is created, you can specify SpreadsheetDatastore properties and use functions that access and manage the data.

Creation

Create SpreadsheetDatastore objects using the spreadsheetDatastore function or the datastore function.

Properties

SpreadsheetDatastore PropertiesAccess and modify SpreadsheetDatastore properties

Object Functions

hasdataDetermine if data is available to read
numpartitionsNumber of datastore partitions
partitionPartition a datastore
previewSubset of data in datastore
readRead data in datastore
readallRead all data in datastore
resetReset datastore to initial state
sheetnamesQuery sheet names from datastore

Examples

expand all

Create a SpreadsheetDatastore object containing the file airlinesmall_subset.xlsx.

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

  SpreadsheetDatastore with properties:

                      Files: {
                             ' ...\matlab\toolbox\matlab\demos\airlinesmall_subset.xlsx'
                             }
                     Sheets: ''
                      Range: ''

  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'

Display the sheet names for the file. The file contains one sheet per year.

sheetnames(ssds,1)
ans = 

  Columns 1 through 7

    '1996'    '1997'    '1998'    '1999'    '2000'    '2001'    '2002'

  Columns 8 through 13

    '2003'    '2004'    '2005'    '2006'    '2007'    '2008'

Specify the variable FlightNum in the second sheet as the data of interest, and preview the first eight rows.

ssds.Sheets = 2;
ssds.SelectedVariableNames = 'FlightNum';
preview(ssds)
ans = 

    FlightNum
    _________

    1014     
    1201     
     702     
    1184     
    1310     
    1759     
    1242     
    1558     

Read only the first three rows of variables DepTime and ArrTime in the first sheet.

ssds.ReadSize = 3;
ssds.Sheets = 1;
ssds.SelectedVariableNames = {'DepTime','ArrTime'};
read(ssds)
ans = 

    DepTime    ArrTime
    _______    _______

    2117       2305   
    1252       1511   
    1441       1708   

Read all of sheets four, five, and six.

ssds.Sheets = 4:6;
readall(ssds);

Introduced in R2016a

Was this topic helpful?