Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mlreportgen.dom.StyleRef class

Package: mlreportgen.dom
Superclasses:

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.

Construction

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.

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.

Output Arguments

expand all

Referenced object, returned as an mlreportgen.dom.StyleRef object.

Properties

expand all

This read-only property lists child elements of this object.

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. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

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

This read-only property lists the parent of this document element.

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 document element, specified as a character vector.

A session-unique ID is generated as part of document element creation. The generated tag has the form CLASS:ID, where CLASS is the class of the element and ID is the value of the Id property of the object. You can specify a tag to replace the generated tag.

For example, to make it easier to identify where an issue occurred during document generation, you can specify your own tag value.

Methods

Method

Purpose

clone

Copy this object.

Examples

expand 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);

Introduced in R2016a

Was this topic helpful?