Categories &

Functions List

Function Reference: ods2struct

datatypes: s = ods2struct (filename)

Read every sheet of an OpenDocument spreadsheet into a scalar structure.

s = ods2struct (filename) reads each data sheet of the OpenDocument spreadsheet named by filename into a table and returns a scalar structure with one field per sheet, in sheet order. Both the compressed .ods and the flat .fods formats are read. Each sheet is reconstructed exactly as by ods2table; it is the inverse of struct2ods.

A sheet name that is not a valid structure field name is canonicalised with matlab.lang.makeValidName (and made unique if two sheet names collide). Whenever the field name differs from the sheet name, the original sheet name is stored on that field’s table as the 'ActualSheetName' custom property, so a subsequent struct2ods restores the exact sheet name.

See also: struct2ods, ods2table, table2ods, readtable

Source Code: ods2struct

Example: 1

ods2struct is the inverse of struct2ods: it reads every data sheet of a workbook into one scalar struct, one field per sheet, in sheet order.

 wb.Patients = table ({'Li'; 'Diaz'}, [38; 40], 'VariableNames', {'Name', 'Age'});
 wb.Visits = table ([1; 2; 3], 'VariableNames', {'Visit'});
 filename = fullfile (tempdir (), 'clinic.ods');
 struct2ods (filename, wb);
 s = ods2struct (filename);
 s.Patients
ans =
  2x2 table

      Name      Age    
    ________    ___    

    {'Li'  }     38    
    {'Diaz'}     40
 delete (filename);