Main Content

Report Formatting Approaches

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

Style Sheets in Templates

DOM API带有每种输出类型的默认模板,以使其生成报告。您可以自定义这些模板以指定报告的默认格式和布局。看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 stylemyparathat uses one set of formats, such as font size, emphasis, and font family. You define another paragraph style named你的帕拉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使用样式表格.

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 aStyleproperty that you can set to a cell array of format objects. You can use format objects with the document objectStyleproperty to format the object. For example, this code uses format objects to specify the style of a warning paragraph.

importmlreportgen.dom.*p =段落('危险!'); p.Style = {Color(“红色”),FontFamily('Arial'),FontSize('18pt')};

It is a best practice to set theStyleproperty by concatenating the existing value of theStyleproperty and the cell array of format objects that you are adding. For example:

importmlreportgen.dom.*p =段落('危险!'); p.Style = [p.Style {Color(“红色”),FontFamily('Arial'),FontSize('18pt')}];

This practice prevents inadvertent removal of format objects that you previously added or that the DOM API added to synchronize theStyleproperty with the format properties. SeeFormat Properties.

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:

importmlreportgen.dom.*warning = {Color(“红色”),FontFamily('Arial'),FontSize('18pt')}; p = Paragraph('危险!'); p.Style = [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

大多数DOM对象都有一组属性,该属性对应于最常用于该类的对象的格式选项。例如,此代码使用段落中的字体和颜色来设置文本的字体和颜色Color,FontFamily, andFontSizeformat properties of aParagraph目的。

importmlreportgen.dom.*p =段落('危险!'); p.Color =“红色”; p.FontFamilyName ='Arial'; p.FontSize ='18pt';

相关话题