Main Content

mlreportgen.dom.StyleRef Class

Namespace: mlreportgen.dom

Placeholder for reference to content with specified style name or outline level

Description

Create a placeholder for a reference to content that has a specified style name or outline level. This object applies to Word and PDF reports.

For a Microsoft® Word document, you can append a StyleRef object to the header, footer, or in the body text. For PDF, you can append a StyleRef object only to the header or footer.

Tip

Use StyleRef objects to create running headers and footers in your document. For example, you can use this object to add the title of the current chapter in the page header.

The mlreportgen.dom.StyleRef class is a handle class.

Creation

Description

styleref = StyleRef creates a reference to the content of the paragraph nearest to this object whose OutlineLevel property of 1.

In the headers of Word output, the nearest paragraph is the first paragraph on the current page that has the specified outline level. If there is no such paragraph on the current page, the nearest paragraph is the first paragraph on pages before or after the current page that has the specified outline level.

In the footers of Word output, the nearest paragraph is the last paragraph on the current page that has the specified outline level. If there is no such paragraph on the current page, the nearest paragraph is the first paragraph on pages before or after the current page that has the specified outline level.

In page headers and footers in PDF output, the nearest paragraph is the first paragraph on the current page or on pages in the current page layout section before or after the current page.

styleref = StyleRef(num) creates a reference to the content of the paragraph nearest to this object whose OutlineLevel property has the specified level.

styleref = StyleRef(styleName) creates a reference to the content of the paragraph nearest to this object that has the specified style name.

example

Input Arguments

expand all

Level of the heading object to reference, specified as a positive integer.

Name of style of object to reference, specified as a character vector or string scalar.

Properties

expand all

Custom attributes of this document element, specified as an array of mlreportgen.dom.CustomAttribute objects. The custom attributes must be supported by the output format of the document element to which this object is appended.

Attributes:

NonCopyable
true

Outline (heading) level of object to reference, specified as a positive integer. The default level is 1.

Data Types: int32

Style sheet style to apply to the reference, specified as a character vector or string scalar.

Format specification for this document element object, specified as an array of DOM format objects. The formats specified by this property override corresponding formats specified by the StyleName property of this element. Formats that do not apply to this document element object are ignored.

Attributes:

NonCopyable
true

Style name, specified as a character vector or string scalar. The style name is the name of a style specified in the style sheet of the document or document part to which this element is appended. The specified style defines the appearance of this element in the output document unless overridden by the formats specified by the Style property of this element. To learn more about using style sheets, see Use Style Sheet Styles.

Note

Microsoft Word output ignores the style name.

Attributes:

NonCopyable
true

Data Types: char | string

Parent of mlreportgen.dom.StyleRef object, specified as a document element object. A document element must have only one parent.

Attributes:

SetAccess
private
NonCopyable
true

Children of mlreportgen.dom.StyleRef object, specified as an array of document element objects. This property contains the document element objects appended using the append method.

Attributes:

SetAccess
private
NonCopyable
true

Tag for the mlreportgen.dom.StyleRef object, specified as a character vector or string scalar. The DOM API generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specify your own tag value to help you identify where to look when an issue occurs during document generation.

Attributes:

NonCopyable
true

Data Types: char | string

Object identifier for the mlreportgen.dom.StyleRef object, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object. You can specify your own value for Id.

Attributes:

NonCopyable
true

Data Types: char | string

Methods

expand all

Examples

collapse all

This example uses an outline level to specify the content of a running footer.

import mlreportgen.dom.*;
d = Document('mydoc','pdf');
open(d);

% Create page footer
footer = PDFPageFooter('default');
d.CurrentPageLayout.PageFooters = footer;

% Define and the StyleRef object using default (first level heading)
% Append it to the footer
ref = StyleRef();
append(footer,ref);

% Create several pages
% The footer content changes based on the last Heading1 object
h = Heading1('My First Head');
p = Paragraph('The above heading appears in the footer because it is a level 1 head.');
append(d,h);
append(d,p);

h2 = Heading1('My Next Head');
h2.Style = {PageBreakBefore(true)};
p2 = Paragraph('Now the above heading appears in the footer.');

append(d,h2);
append(d,p2);

h3 = Heading1('My Third Head');
h3.Style = {PageBreakBefore(true)};
append(d,h3);
append(d,clone(p2));

p3 = Paragraph(['Because I have not added another Heading1 object '...
    'since the last one, the heading from the previous page appears in the footer.']);
p3.Style = {PageBreakBefore(true)};
append(d,p3);

close(d);
rptview(d.OutputPath);

This example shows how to specify a style name for the contents of the reference. This example creates two StyleRef objects: one that uses the default value (Heading1 objects) and one that uses the content of a paragraph formatted with the Subtitle style name. You insert both objects in the footer so that the footer contains text in the form [Most Recent Heading1 Name]: [Most Recent Subtitle Name].

import mlreportgen.dom.*;
d = Document('mydoc','docx');
open(d);

% Create page footer
footer = DOCXPageFooter('default');
d.CurrentPageLayout.PageFooters = footer;

% Create two StyleRef objects. ref uses content of Heading1 objects;
% ref2 uses content of paragraphs that use Subtitle style name.
ref = StyleRef();
ref2 = StyleRef('Subtitle');

% Assemble the footer text
footpara = Paragraph();
footpara.WhiteSpace = 'preserve';
append(footpara,ref);
append(footpara,': ');
append(footpara,ref2);
append(footer,footpara);

% Create Heading1 and Subtitle paragraphs
% Footers update based on most recent values
h = Heading1('My Document Title');
sub = Paragraph('Subtitle Text');
sub.StyleName = 'Subtitle';
p = Paragraph('Here''s some text.');
append(d,h);
append(d,sub);
append(d,p);

sub2 = Paragraph('Another Subtitle');
sub2.StyleName = 'Subtitle';
sub2.Style = {PageBreakBefore(true)};
append(d,sub2);
append(d,clone(p));

close(d);
rptview(d.OutputPath);

Version History

Introduced in R2016a