MATLAB: How to style Report Generator lists programmatically

boldcolorfontgeneratoritaliclistMATLABreportstyle

Can list contents be styled (color, italic, etc) programmatically (as opposed to interactively) for the .docx type specifically?

Best Answer

First, this documentation page shows several methods of creating lists programmatically:
Note that with these methods, you can first use "Text" to create a text object to be added to the document. Several properties of the text object can be adjusted programmatically. These include the properties 'Bold', 'Italic', 'Color', and 'FontSize'. You can then concatenate these styled text objects into a cell array to be appended as a list.
Below is a short example that generates a report with a list where the items have some of these characteristics:
% Set up report
import mlreportgen.dom.*;
d = Document('myListReport','docx');
% Make the first item bold
b = Text('first item');
b.Bold = true;
% Make the second item italic
it = Text('second item');
it.Italic = true;
% Make the third item bold and italic
bit = Text('third item');
bit.Bold = true;
bit.Italic = true;
% Make the fourth item large and red
fnt = Text('fourth item');
fnt.Color = 'red';
fnt.FontSize = '25';
% Add items to the report and view the report
append(d,{b, it, bit, fnt});
close(d);
rptview(d.OutputPath);