Documentation

SpreadsheetDatastore

Datastore for spreadsheet files

Description

SpreadsheetDatastoreobjects are associated with large collections of spreadsheet files where the collection does not necessarily fit in memory. You can use thespreadsheetDatastorefunction or thedatastorefunction to create aSpreadsheetDatastoreobject. Once the object is created, you can specifySpreadsheetDatastoreproperties and use functions that access and manage the data.

Creation

CreateSpreadsheetDatastoreobjects using thespreadsheetDatastorefunction or thedatastorefunction.

Properties

SpreadsheetDatastore属性 Access and modify SpreadsheetDatastore properties

Object Functions

hasdata Determine if data is available to read
numpartitions Number of datastore partitions
partition Partition a datastore
preview Subset of data in datastore
read Read data in datastore
readall Read all data in datastore
reset Reset datastore to initial state
sheetnames Query sheet names from datastore

Examples

expand all

Create aSpreadsheetDatastoreobject containing the fileairlinesmall_subset.xlsx.

ssds = spreadsheetDatastore('airlinesmall_subset.xlsx')
ssd =电子表格Datastore 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 variableFlightNumin 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 variablesDepTimeandArrTimein 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?