Main Content

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 aStyleRefobject to the header, footer, or in the body text. For PDF, you can append aStyleRefobject only to the header or footer.

Tip

UseStyleRef对象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 whoseOutlineLevelproperty of1.

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 whoseOutlineLevelproperty 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 anmlreportgen.dom.StyleRefobject.

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 ofmlreportgen.dom.CustomAttribute对象. Use custom attributes supported by the output format.

本文档ID元素,指定为一个性格cter vector or string scalar. 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.

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

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

Methods

Method

Purpose

clone

Copy this object.

Examples

collapse all

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

importmlreportgen.dom.*; d = Document('mydoc','pdf'); open(d);% Create page footerfooter = PDFPageFooter('default'); d.CurrentPageLayout.PageFooters = footer;% Define and the StyleRef object using default (first level heading)% Append it to the footerref = StyleRef(); append(footer,ref);% Create several pages% The footer content changes based on the last Heading1 objecth = 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 twoStyleRef对象: one that uses the default value (Heading1对象) and one that uses the content of a paragraph formatted with theSubtitlestyle 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].

importmlreportgen.dom.*; d = Document('mydoc','docx'); open(d);% Create page footerfooter = 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 textfootpara = 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 valuesh = Heading1('My Document Title'); sub = Paragraph('Subtitle Text'); sub.StyleName ='Subtitle'; p = Paragraph(这里的“年代一些文本。); 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