Spreadsheets

Microsoft® Excel® spreadsheets

Read and write data in spreadsheet files, including .xls and .xlsx files into tables, timetables, matrices, or arrays in MATLAB®. You can import spreadsheet data interactively using the Import Tool or you can import data programmatically using the functions listed here. You can import a selected range of data or you can import multiple worksheets from spreadsheet files.

Functions

expand all

Import ToolImport data from file

Basic Import and Export

readtableCreate table from file
writetableWrite table to file
readtimetableCreate timetable from file
writetimetableWrite timetable to file
sheetnamesGet sheet names from spreadsheet file

Define Import Rules

detectImportOptionsCreate import options based on file content
spreadsheetImportOptionsImport options object for Spreadsheets
getvaroptsGet variable import options
setvaroptsSet variable import options
setvartypeSet variable data types
previewPreview eight rows from file using import options
readmatrixRead matrix from file
writematrixWrite a matrix to a file
readcellRead cell array from file
writecellWrite cell array to file
readvarsRead variables from file
importdataLoad data from file

Objects

spreadsheetDatastoreDatastore for spreadsheet files

Topics

Read Spreadsheet Data

Import Spreadsheets

Spreadsheets often contain a mix of numeric and text data as well as variable and row names, which is best represented in MATLAB as a table.

Read Spreadsheet Data Using Import Tool

Preview spreadsheet data from a file or the clipboard and select data to import using the Import tool.

Read Spreadsheet Data into Table

The best way to represent tabular spreadsheet data in MATLAB is in a table since tables can store heterogeneous (a mix of numeric and text) data, as well as variable and row names.

Read Spreadsheet Data into Array or Individual Variables

In addition to importing data as a table using readtable, you can also import data as a matrix, a cell array, or import separate variables directly in to the workspace.

Read Collection or Sequence of Spreadsheet Files

Read and manage data from a collection of spreadsheet files.

Define Import Options for Tables

If you want to control the import process beyond the options provided by the readtable function, such as defining how to handle missing data or errors, then create an import options object before importing the data.

Write Spreadsheet Data

Write Data to Excel Spreadsheets

Export data in the workspace to a Microsoft Excel spreadsheet file.