struct2ods
datatypes: struct2ods (filename, s)
Write a scalar structure of tables to a multi-sheet OpenDocument spreadsheet.
struct2ods (filename, s) writes each field of the scalar
structure s to its own sheet in the OpenDocument spreadsheet named by
filename. Every field of s must hold a table; the field
name becomes the sheet name. Both the compressed .ods and the flat
.fods formats are supported, selected by the file extension.
Full type fidelity is preserved through a hidden, sectioned
__datatypes_meta__ sheet, exactly as for the single-table
table2ods method; the workbook round-trips through ods2struct.
A field whose table carries an 'ActualSheetName' custom property
(see addprop) uses that value as the sheet name instead of the field
name, which lets a sheet name that is not a valid identifier (for example
'Sales 2024') round-trip. Sheet names must be non-empty and must not
contain any of the characters [ ] * ? : / , and the
resolved names must be unique.
See also: ods2struct, table2ods, ods2table, writetable
Source Code: struct2ods
struct2ods writes a whole workbook at once: each field of a scalar struct of tables becomes its own sheet, and the field name becomes the sheet name.
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);
The two fields are now two sheets, recoverable with ods2struct.
fieldnames (ods2struct (filename))
ans =
2x1 cell array
{'Patients'}
{'Visits' }
delete (filename);