XLS (.xls)

Background & Context

    • Registered MIME type: application/vnd.ms-excel
    • Microsoft Excel spreadsheet file.
    • XLS is an acronym derived from Excel Spreadsheet.
    • Stores spreadsheet data and formulas.

Import & Export

  • Import["file.xls"] imports all sheets of an XLS file, returning the result as a list of arrays.
  • Each sheet is imported as a full array containing numerical and textual data, Boolean values and date objects.
  • Import["file.xls",elem] imports the specified element from an XLS file.
  • Import["file.xls",{elem,sub1,}] imports subelements specifically useful for partial data import.
  • The import format can be specified with Import["file","XLS"] or Import["file",{"XLS",elem,}].
  • Export["file.xls",expr] exports an array or a list of arrays to XLS.
  • Export["file.xls",expr] also works for structured input such as Dataset, Grid and TimeSeries.
  • Export["file.xls",expr, elem] creates an XLS file by treating expr as specifying element elem.
  • Export["file.xls",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.xls",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the XLS format.

Import Elements

  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Basic information element:
  • "Dimensions"association of sheet names and sheet dimensions
    "SheetCount"number of sheets
    "Sheets"list of sheet names
  • Data representation elements:
  • "Data"list of full arrays, representing all sheets
    "Dataset"list of Dataset objects, representing all sheets
    "FormattedData"data with some styling elements applied
    "Formulas"all formulas as text
    "Images"embedded images as a list
  • Import and Export by default use the "Data" element.
  • Any data representation element can specify {elem,sheets,rows,cols} to extract parts of an XLS file.
  • Part specification sheet can be any of the following:
  • nnth sheet
    -ncounts from the end
    namesheet name
    n;;msheets n through m
    n;;m;;ssheets n through m with steps of s
    {n1,name,}specific name or sheet index ni
  • Part specifications row and col can be any of the following:
  • nnth row or column
    -ncounts from the end
    n;;mfrom n through m
    n;;m;;sfrom n through m with steps of s
    {n1,n2,}specific sheet index ni or name
  • XLS data is represented in the Wolfram Language by real or integer numbers, strings, Boolean values True and False, and DateList specifications.
  • Import["file.xls","Formulas"] gives the Excel formulas for each cell in the form {f1,f2,}, where the fi are arrays corresponding to the sheets of an XLS file.
  • Import yields spreadsheets as full rectangular arrays.
  • Export supports full and ragged arrays.


  • Import and Export options:
  • "EmptyField"""how empty cells are represented in Wolfram Language
  • Import options:
  • "HeaderLines"0number of lines to assume as headers
    "SkipLines"0number of lines to skip at the beginning of the file
  • Possible settings for "HeaderLines" and "SkipLines" are:
  • nn rows to skip or to use as Dataset headers
    {rows,cols}rows and columns to skip or to use as headers
  • Export options:
  • "ImageFormat""JPEG"format used for exporting images


open allclose all

Basic Examples  (4)

Import the first sheet of an XLS file:

Embed graphics in an XLS file:

Import an embedded image from an XLS file:

Export the first 12 prime numbers to a spreadsheet:

Export two datasets to different sheets:

Scope  (6)

Show the Import elements in a file:

Specify sheet names:

Import the cell at row 1, column 4 for a given sheet:

Import the second sheet:

Export date and date-time stamps:

Import converts a date into a DateObject:

Export raster images to XLS (automatically rasterizing vector graphics):

Import returns a list of images:

Raw bytes representing common image file formats can also be exported as images to XLS:

Export a Dataset:

Use the "HeaderLines" option to import table headers:

Import Elements  (13)

"Data"  (6)

Import an XLS file as a 3D list of values:

This is also the default element:

Import the first sheet of an XLS file:

Import a single row from a sheet in an XLS file:

Import a single column from a sheet in an XLS file:

Import the first 3 rows of a named sheet:

"Dataset"  (1)

Import the first sheet of an XLS file as a Dataset:

Use the first row as header:

"Dimensions"  (1)

Import the dimensions of the sheets in an XLS file:

"FormattedData"  (1)

Import XLS data, preserving basic formatting with Style:

"Formulas"  (1)

Import the raw data of all formula cells in an XLS file:

"Images"  (1)

Import an embedded image from an XLS file:

"SheetCount"  (1)

Import the number of sheets in an XLS file:

"Sheets"  (1)

Import the names of the sheets in an XLS file:

Import Options  (6)

"EmptyField"  (1)

Some XLS files may contain empty cells. Create a file with some empty fields:

By default, empty fields are imported as empty strings "":

Specify the value of empty fields:

"HeaderLines"  (4)

By default, no row or column is assumed to be a header line:

Specify column headers:

Specify row headers:

Specify row and column headers:

"SkipLines"  (1)

Some XLS sheets may include a comment line.

Skip the comment line:

Skip the comment line, and use the next line as a Dataset header:

Possible Issues  (2)

The top-left corner of data is lost when importing a Dataset with row and column headers:

Dataset may look different depending on the dimensions of the data: