Main Content

mlreportgen.dom.TemplateStylesheet Class

Namespace: mlreportgen.dom

MATLAB representation of template style sheet

Since R2024a

Description

The mlreportgen.dom.TemplateStylesheet class contains the styles for a mlreportgen.dom.Template object. On opening, the mlreportgen.dom.Template creates an instance of mlreportgen.dom.TemplateStylesheet in its Stylesheet property. Creating the mlreportgen.dom.Template object, which is based on the source template document, automatically populates its Stylesheet property with the styles already present in the source template. Use the methods of this class to add, remove, or replace styles. The parent mlreportgen.dom.Template object generates all styles in the TemplateStylesheet object in the resulting template document.

Note

DOM format classes such as mlreportgen.dom.Bold and mlreportgen.dom.Color define the formatting for new styles. DOM template style classes do not support these formatting classes:

  • ListStyleType

  • NumberFormat

  • OutlineLevel

  • ScaleToFit

DOM template style classes for DOCX template output do not support these DOM format classes:

  • CounterInc

  • CounterReset

  • FlowDirection (supported for TemplateParagraphStyle only)

  • Height

  • ResizeToFitContents

  • RowHeight

  • TextOrientation

  • Width

  • WhiteSpace

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

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Text styles defined in the style sheet, specified as an array of DOM mlreportgen.dom.TemplateTextStyle objects. To add or remove styles, use the addStyle, removeStyle, or replaceStyle methods.

Attributes:

SetAccess
protected

Paragraph styles defined in the style sheet, specified as an array of DOM mlreportgen.dom.TemplateParagraphStyle objects. To add or remove styles, use the addStyle, removeStyle, or replaceStyle methods.

Attributes:

SetAccess
protected

Linked styles, which are the styles that can be applied to both text and paragraph document elements objects, defined in the style sheet, specified as an array of DOM TemplateLinkedStyle objects. To add or remove styles, use the addStyle, removeStyle, or replaceStyle methods.

Attributes:

SetAccess
protected

Existing styles defined in the source template, specified as an array of mlreportgen.dom.TemplateDOCXStyle, mlreportgen.dom.TemplateHTMLStyle, and mlreportgen.dom.TemplatePDFStyle objects. To add or remove styles, use the addStyle, removeStyle, or replaceStyle methods.

Attributes:

SetAccess
protected

Tag for mlreportgen.dom.TemplateStylesheet 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 mlreportgen.dom.TemplateStylesheet 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

Add stylesheet content to a new template.

Import the DOM API namespace so you do not have to include the fully qualified names.

import mlreportgen.dom.*

Create a DOCX template.

t = Template("bookReportTemplate","docx");
open(t);

Create a text style.

textStyle = TemplateTextStyle("exampleTextStyle");

Format the text style.

textStyle.Formats = [Bold(true),Color("red")];

Add the text style to the stylesheet.

stylesheet = t.Stylesheet;
addStyle(stylesheet,textStyle);

close(t);

View an existing style in a DOCX template, create a new style with modifications to that style, and replace the existing style with the modified style.

Create a DOCX Template and Examine the Default Style

Import the DOM API namespace so you do not have to use fully qualified names.

import mlreportgen.dom.*

Create a template using the default DOCX template.

t = Template("myTemplate","docx");

Open the template and check if the "rgMATLABTABLE" style exists.

open(t);
stylesheet = t.Stylesheet;
tableStyle = getStyle(stylesheet,"rgMATLABTABLE")
tableStyle = 
  TemplateDOCXStyle with properties:

       Name: 'rgMATLABTABLE'
       Type: 'table'
    Formats: []
        Tag: 'dom.TemplateDOCXStyle:1738'
         Id: '1738'

Open the source template in Microsoft® Word.

rptview(t.TemplatePath);

Open the source template in Word. In Word, inspect the "Title" style in the source DOCX template.

Create a Modified Style and Replace the Default Style

Create a new table style named "rgMATLABTABLE".

newTableStyle = TemplateTableStyle("rgMATLABTABLE");

Define formats similar to the style from the source template by using the same font, line spacing, and widow and orphan handling.

oldFormats = [LineSpacing(1),FontFamily("Calibri"),WidowOrphanControl];

Leave a 15-point space after the table.

om = OuterMargin;
om.Bottom = "15pt";
oldFormats(end + 1) = om;

Define a format that gives the table a solid border.

newFormat = Border("solid","blue");

Set the formats of the new style.

newTableStyle.Formats = [oldFormats,newFormat];

Replace the old style with the new style.

replaceStyle(stylesheet,newTableStyle);

Close the template.

close(t);
rptview(t);

Version History

Introduced in R2024a