User`s guide

13 Create a Report Program
13-50
}
For more information about using HTML styles with DOM objects, see “Modify Styles in
an HTML Template” on page 13-127.
Apply a Style to a Paragraph Object
Apply a template style to a Paragraph object either as the second argument in a
Paragraph object constructor or by setting the StyleName property to a template
style. For example, suppose you have defined styles named BodyPara and TableTitle
in the template for your report. This example specifies a style name in a Paragraph
constructor and in a Paragraph object StyleName format property, using the
TableTitle style defined in MyTemplate.
import mlreportgen.dom.*;
rank = 5;
rpt = Document('MyReport','html','MyTemplate');
p = Paragraph('Here is a magic square or rank 5:','BodyPara');
append(rpt,p);
p = Paragraph(sprintf('Rank %d MagicSquare',rank));
p.StyleName = 'TableTitle';
append(rpt,magic(rank));
close(rpt);
rptview(rpt.OutputPath);
Override Template Formats
You can use programmatic formats to override the paragraph formats defined in a
template-based paragraph style. For example, suppose you define a paragraph style
named BodyPara in your Word template and set the KeepWithNext property to off. You
can override the style in your report program to keep a particular paragraph on the same
page with the next paragraph. For example:
import mlreportgen.dom.*;
rpt = Document('MyReport','docx','MyTemplate');
p = Paragraph('Keep this body paragraph with next.','BodyPara');
p.Style = {'KeepWithNext'};
append(rpt,p);
p = Paragraph('Next paragraph.');