User`s guide

Use Style Sheets
13-21
Use Style Sheets
A style is a collection of formats that together define the appearance of a document
object, such as a paragraph, table, or list. Microsoft Word allows you to define styles and
then assign them to paragraphs, tables, and other documents by name. The assigned
style then determines how Word renders the document object on the screen or printed
page. Word stores the styles in a document as an object called a style sheet. HTML
browsers support a similar capability.
DOM API objects that have a StyleName property allow you to leverage Word and
HTML style sheets to format reports as follows.
1
Create a Word or HTML template, using the DOM API or a Word or HTML editor,
depending on the report type.
2
Optionally, you can change a template style definition or add a new style. For
details, see “Modify Styles in a Microsoft Word Template” on page 13-117 or
“Modify Styles in an HTML Template” on page 13-127.
3
In a DOM report, create a Document object that uses the template.
4
Assign the names of styles defined in the style sheet to the StyleName property of
objects that you want to have the specified style.
For example, the following script assigns a style named Warning to a paragraph object.
It assumes that you have defined the Warning style previously in a Word template
named MyTemplate.dotx.
d = Document('MyDoc','docx','MyTemplate');
p = Paragraph('Danger');
p.StyleName = 'Warning';
append(d,p);
close(d);
Assigning the Warning style to the DOM paragraph object causes Word to use the
Warning style to render the generated paragraph when you open the generated report.
Tip Some document object constructors allow you to specify the value of the StyleName
property as an argument. For example, this paragraph has the text Danger and uses a
style defined for the template style named Warning.
p = Paragraph('Danger','Warning');