ods2table
datatypes: tbl = ods2table (filename)
datatypes: tbl = ods2table (filename, 'Sheet', sheet)
datatypes: [tbl, rowTimesName] = ods2table (…)
Read an OpenDocument spreadsheet file into a table.
tbl = ods2table (filename) reads the OpenDocument
spreadsheet named by filename, which may be a character vector, a
cellstr, or a string scalar, and returns it as a table. Both the
compressed .ods and the flat .fods formats are read; the
format is detected from the file contents, not its extension.
The following Name-Value options are supported:
| Name | Value |
|---|---|
'Sheet' | The sheet to read, selected by its name (a character vector or string scalar) or by a 1-based index over the data sheets. The default is the first data sheet. |
'ReadVariableNames' | A logical scalar specifying whether
the variable names are taken from the file (default true). Setting
it false numbers the variables Var1, Var2, and so on. |
'ReadRowNames' | A logical scalar specifying whether the
table takes row names from the file (default true). Setting it
false leaves the table without row names. |
'VariableNamesRow' | A nonnegative integer scalar naming the
row of the sheet that holds the variable names (default 1). Zero is
equivalent to setting 'ReadVariableNames' to false. It
applies only to a sheet with no metadata; a sheet written by
table2ods records the names, so there is no row to name. |
'RowNamesColumn' | A nonnegative integer scalar naming the
column of the sheet that holds the row names (default 0). Zero is
equivalent to setting 'ReadRowNames' to false. It applies
only to a sheet with no metadata, which says nothing about which column holds
row names; a sheet written by table2ods records the column. A leading
column headed Row, which is what writetable writes for the row
names, is taken as the row names without being named here. |
Source Code: ods2table
When the file carries the hidden __datatypes_meta__ sheet written by
the table2ods method, the variable types, descriptions and units are
restored from it and the variable names from the rows heading the data
sheet, and date and time cells are
reconstructed as datetime and duration arrays. Integers are
restored without loss of precision and missing cells become NaN,
NaT, or missing strings as appropriate. A file written before the
names moved to the data sheet carries them on the metadata sheet, and is
read just as well. A sheet whose cells contradict the types its metadata
declares, such as text under a numeric type after another program rewrote
the sheet, raises an error.
A sheet written from a timetable tags its leading column as row times. A
table has no row times, so the column is returned as an ordinary leading
variable under the row dimension name, and the second output
rowTimesName names it; rowTimesName is empty for every other
sheet, which is how ods2struct tells a sheet that held a timetable
from one whose first variable merely happens to be a datetime. Read
such a sheet with ods2timetable to get the timetable back.
When the metadata sheet is absent (a spreadsheet written by another application) the variable types are inferred from the cell value types. Where no names are available the variables are numbered, and the columns can then no longer be grouped, so a multicolumn variable comes back as separate variables and a nested table as flat columns.
A datetime or duration variable is restored exactly, along
with its Format and, for a zone-aware datetime, its
TimeZone. A cell that carries no value at all is a missing entry,
which is not the same as a cell holding an empty string. The following
round-trip limitation applies, mirroring csv2table:
calendarDuration and categorical variables are returned as cell
arrays of character vectors and their values are not reconstructed.
Source Code: ods2table
ods2table reads an OpenDocument spreadsheet into a table. With no options it reads the first data sheet.
T = table ([38; 43], [71; 69], 'VariableNames', {'Age', 'Height'});
filename = fullfile (tempdir (), 'patients.ods');
table2ods (T, filename);
ods2table (filename)
ans =
2x2 table
Age Height
___ ______
38 71
43 69
Point 'Sheet' at a specific sheet, by name or by 1-based index, to read one page of a multi-sheet workbook.
filename = fullfile (tempdir (), 'workbook.ods');
table2ods (table ([38; 43], 'VariableNames', {'Age'}), filename, 'Sheet', ...
'Patients');
table2ods (table ([1; 2; 3], 'VariableNames', {'Visit'}), filename, ...
'Sheet', 'Visits');
ods2table (filename, 'Sheet', 'Visits')
ans =
3x1 table
Visit
_____
1
2
3
delete (filename);