clone
Class: mlreportgen.dom.Paragraph
Namespace: mlreportgen.dom
Copy paragraph object
Description
copies
(clones) the specified paragraph. The resulting cloned paragraph includes
the children of the source paragraph, but not the parent.clonedPara
= clone(sourcePara
)
Examples
Input Arguments
Output Arguments
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.
Create a paragraph that uses a style that sets the
Bold
andItalic
formats totrue
.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
Clone the paragraph. The
Bold
andItalic
formats are the same as those of the source paragraph.pClone = clone(p); pClone.Bold
ans = 1
p.Italic
ans = 1
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
In the style object (
MyStyle
) for the source paragraph, turn off italics. Now the cloned paragraph does not use italics, because it shares theMyStyle
setting for theItalics
format.MyStyle(2).Value = false pClone.Italic
ans = 0
Version History
Introduced in R2014b