struct2xlsx
datatypes: struct2xlsx (filename, s)
Write a scalar structure of tables to a multi-sheet Excel workbook.
struct2xlsx (filename, s) writes each field of the scalar
structure s to its own sheet in the Office Open XML workbook named by
filename (.xlsx or .xlsm). Every field must hold a
table; the field name becomes the sheet name.
This is the Excel counterpart of struct2ods. Like writetable,
it writes the MATLAB-interoperable format (a variable-name header row followed
by the data, with no hidden type metadata); read it back with
xlsx2struct. A field whose table carries an 'ActualSheetName'
custom property uses that value as the sheet name instead of the field name.
Sheet names must be non-empty, at most 31 characters, and must not contain any
of the characters [ ] * ? : / ; the resolved names
must be unique.
See also: xlsx2struct, struct2ods, writetable, readtable
Source Code: struct2xlsx
struct2xlsx is the Excel counterpart of struct2ods: each field of a scalar struct of tables is written as its own worksheet in an .xlsx file.
wb.Patients = table ({'Li'; 'Diaz'}, [38; 40], 'VariableNames', {'Name', 'Age'});
wb.Visits = table ([1; 2; 3], 'VariableNames', {'Visit'});
filename = fullfile (tempdir (), 'clinic.xlsx');
struct2xlsx (filename, wb);
Read it back with xlsx2struct to recover the same field names.
fieldnames (xlsx2struct (filename))
ans =
2x1 cell array
{'Patients'}
{'Visits' }
delete (filename);