Report Formatting Approaches

You can format your report using style sheets, format objects, format properties, or any combination of these approaches.

Style Sheets in Templates

The DOM API comes with default templates for each output type for formatting your report as it generates. You can customize these templates to specify the default formatting and layout of your reports. See Templates for DOM API Report Programs.

Use style sheets in a template to describe the default formatting of document objects like paragraphs, headers, and tables. A style sheet is a collection of formatting styles. A style is a named collection of formats for a particular type of object or, in the case of HTML and PDF, for a particular type of object that appears in a particular context in your document. For example, you can define a paragraph style MyPara that uses one set of formats, such as font size, emphasis, and font family. You define another paragraph style named YourPara that uses a different set of formats. When you write your report program, you assign the style to a paragraph object by name. For an example, see Use Style Sheet Styles.

Format Objects

A format object is a MATLAB® object that defines the properties and functions of a document format, such as a font family or size. The DOM API provides a set of constructors for creating format objects corresponding to most of the formatting options available in HTML, Word, and PDF documents. Most DOM document objects include a Style property that you can set to a cell array of format objects. You can use format objects with the document object Style property to format the object. For example, this code uses format objects to specify the style of a warning paragraph.

p = Paragraph('Danger!');
p.Style = {Color('red'),FontFamily('Arial'),FontSize('18pt')};

You can assign the same array of format objects to more than one DOM document object. This technique allows you to create a programmatic equivalent of a template style sheet. For example:

warning = {Color('red'),FontFamily('Arial'),FontSize('18pt')};
p = Paragraph('Danger!');
p.Style = warning;
p = Paragraph('Caution!');
p.Style = warning;

The DOM API allows you to assign any format object to any document object, regardless of whether the format applies. If the format does not apply, it is ignored.

Format Properties

Most DOM objects have a set of properties corresponding to the format options most commonly used for an object of that class. You can use dot notation to specify formats for an object. For example, this code sets the font and color of text in a paragraph, using the Color, FontFamily, and FontSize format properties of a Paragraph object. Each string after the dot corresponds to a format property.

p = Paragraph('Danger!');
p.Color = 'red';
p.FontFamilyName = 'Arial';
p.FontSize = '18pt';

Assigning a value to a format property causes the API to create an equivalent format object and assign it to the Style property of the document object. Similarly, assigning a format object to an object’s Style property causes the API to assign an equivalent value to the corresponding format property, if it exists. In this way, the API keeps format properties for an object synchronized with the Style property of the object.

Note

When you change the value of a format property, the DOM API:

  • Creates a clone of the corresponding format object

  • Changes the value of the clone’s corresponding format object property

  • Replaces the original format object with the clone in the array of format objects assigned to the document object

In this way, the DOM prevents a change in a format property in one object from changing a style originally assigned to other objects.

Related Examples

More About