Main Content

clone

Class: mlreportgen.dom.Paragraph
Namespace: mlreportgen.dom

Copy paragraph object

Description

example

clonedPara = clone(sourcePara) copies (clones) the specified paragraph. The resulting cloned paragraph includes the children of the source paragraph, but not the parent.

Examples

expand all

import mlreportgen.dom.*;
d = Document('myDoc','html');

para1 = Paragraph('This is a paragraph');
para1.Bold = true;
append(d,para1);
para1Copy = clone(para1);
para1Copy
para1Copy = 
  Paragraph with properties:

        OutlineLevel: []
                Bold: 1
              Italic: []
               Color: []
     BackgroundColor: []
           Underline: []
          WhiteSpace: []
      FontFamilyName: []
            FontSize: []
              Strike: []
              HAlign: []
     OuterLeftMargin: []
     FirstLineIndent: []
           StyleName: []
               Style: {[1x1 mlreportgen.dom.Bold]}
    CustomAttributes: []
              Parent: []
            Children: [1x1 mlreportgen.dom.Text]
                 Tag: 'dom.Paragraph:41'
                  Id: '41'

Input Arguments

expand all

Paragraph object to copy, specified as an mlreportgen.dom.Paragraph object.

Output Arguments

expand all

Copied paragraph object, represented by an mlreportgen.dom.Paragraph object.

Tips

  • Use the clone method to append the same paragraph content more than once in a document.

  • When you clone a paragraph, DOM copies all of the children objects of the source paragraph, but not the parent of the paragraph.

  • The cloned paragraph includes formats that you set in the source paragraph. The cloned paragraph formats use the same format objects as the source paragraph. If you change the format setting in the shared format object, the source and cloned paragraphs reflect that change.

    If you change a format setting in the cloned paragraph, then DOM creates a new format object for the cloned paragraph, using the new format setting. For that format, the source and cloned paragraph no longer share the same format object.

    This example shows the relationship between the formats for the source and cloned paragraphs.

    1. Create a paragraph that uses a style that sets the Bold and Italic formats to true.

      import mlreportgen.dom.*;
      myReport = Document('myDoc','html');
      p = Paragraph('This is a paragraph');
      append(myReport,p);
      MyStyle = {Bold,Italic};
      p.Style = MyStyle;
      p.Bold
      ans =
      
           1
      p.Italic
      ans =
      
           1
    2. Clone the paragraph. The Bold and Italic formats are the same as those of the source paragraph.

      pClone = clone(p);
      pClone.Bold
      ans =
      
           1
      p.Italic
      ans =
      
           1
    3. For the cloned paragraph, change turn off bold text. The change to the Bold format in the cloned paragraph does not affect the text for the source paragraph. The source paragraph text is still bold.

      pClone.Bold = false;
      p.Bold
      ans =
      
           1
    4. In the style object (MyStyle) for the source paragraph, turn off italics. Now the cloned paragraph does not use italics, because it shares the MyStyle setting for the Italics format.

      MyStyle(2).Value = false
      pClone.Italic
      ans =
      
           0

Version History

Introduced in R2014b