Reading Data from File

By default, Numbers for Mac and Numbers for iOS support importing the following file formats:

  • Numbers ’09 (2.0 or later)
  • Microsoft Excel - Office Open XML (.xlsx) and Office 97 or later (.xls)
  • Comma Separated Values (CSV)
  • Tab-delimited text files

But opening files is not the only way to add data to a document. Using the scripting support in Numbers 3.1, you can read data directly from files, to use in the creation of new tables, or to fill-in a selection range of an existing table.

This topic concerns how to read and use the contents of Tab Separated Values (TSV) files, like the one shown below:


DEMO CONTENT: Tab-Separated-Values file

The sub-routine shown below, is used by the example scripts in this section to read tabbed data from TSV files:

The result of this sub-routine will be an AppleScript list of data lists, like this:

{{"Sal", "Sue", "Bob", "Carl", "Wanda"}, {"Egbert", "Fred", "Danita", "Shirley", "Scott"}, {"Quincy", "Bertha", "Jane", "Julia", "Frank"}}

For a description of how table data is represented in scripts, see Populating Tables with Data, in the previous section of this site.

Reading Data from File into Selection Range

This script will import and interpret tabbed data from a TSV file, into the selection range of an existing table. To use, select a tange of cells in a table, that matches the parameters of the data to import. For example, if the data in the file consists of three data groups of five data items, then select three rows of cells crossing five columns in the table.

The script will prompt the user to choose the source file, and then declare whether the data is to be row-oriented or column-oriented. It will also check that the data and selection range attributes match.


 (⬆ see above ) Data imported into selection range as column-based data.
 (⬇ see below ) Data imported into selection range as row-based data.


DEMO CONTENT: The tables contained in the Selection Import Example Numbers file, are designed to use the example data file, linked in the first segment at the top of this page.

New Table from File Data

This script reads tabbed data from a TSV file, and creates a new table, on the active sheet, to match the dimensions of the imported data.