Main Content

mlreportgen.dom.StyleRef class

Package: 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.

example

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

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.

Properties

expand all

Children of this document element, specified as an array of DOM objects. This property is read-only.

Custom attributes of this element, specified as an array of mlreportgen.dom.CustomAttribute objects. Use custom attributes supported by the output format.

ID for this document element, specified as a character vector or string scalar. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

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

Parent of this document element, specified as a DOM object. This property is read-only.

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true

Format objects that specify the format of a document element.

Name of the style to apply from the style sheet, specified as a character vector.

Tag for this document element, specified as a character vector or string scalar.

The DOM 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. Specifying your own tag value can help you to identify where an issue occurred during document generation.

Attributes:

GetAccess
public
SetAccess
public
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