Main Content

clone

Class: mlreportgen.ppt.Paragraph
Namespace: mlreportgen.ppt

Copy PPT API paragraph

Since R2021b

Syntax

objCopy = clone(obj)

Description

objCopy = clone(obj) returns a copy of the mlreportgen.ppt.Paragraph object specified by obj. The copy includes the children of the source paragraph, but not the parent.

Input Arguments

expand all

Paragraph object to clone, specified as an mlreportgen.ppt.Paragraph object.

Output Arguments

expand all

Paragraph object copy, returned as an mlreportgen.ppt.Paragraph object.

Examples

expand all

In this example, you use the same paragraph content in two slides by making a copy of the paragraph used in the first slide and appending the copy to the second slide.

Import the PPT API namespace so that you do not have to use long, fully qualified class names.

import mlreportgen.ppt.*;

Create and open a presentation. Add a slide to the presentation.

ppt = Presentation("myPresentation.pptx");
open(ppt);
slide1 = add(ppt,"Title and Content");

Create a Paragraph object and set the Bold and Italic properties to true. Replace the content of slide1 with the Paragraph object.

p = Paragraph("My slide content");
p.Bold = true;
p.Italic = true;
replace(slide1,"Content",p);

Add a second slide to the presentation.

slide2 = add(ppt,"Title and Content");

Make a copy of the Paragraph object that you added to slide1. The attribute values of the copy have the same values as the source Paragraph object.

pcopy = clone(p)
pcopy = 
  Paragraph with properties:

                 Bold: 1
                 Font: []
    ComplexScriptFont: []
            FontColor: []
             FontSize: []
               Italic: 1
               Strike: []
            Subscript: []
          Superscript: []
            Underline: []
               HAlign: []
                Level: []
                Style: {[1×1 mlreportgen.ppt.Bold]  [1×1 mlreportgen.ppt.Italic]}
             Children: [1×1 mlreportgen.ppt.Text]
               Parent: []
                  Tag: 'ppt.Paragraph:15'
                   Id: '15'

Append additional content to the copy of the Paragraph object.

append(pcopy," for the second slide");

Replace the content of the second slide with the copy.

replace(slide2,"Content",pcopy);

Close and view the presentation.

close(ppt);
rptview(ppt);

This example shows the relationship between the formats of a paragraph and a copy of the paragraph.

When you set a format property in a mlreportgen.ppt.Paragraph object, the PPT API adds a corresponding format object to the Style property of the Paragraph object. When you clone a Paragraph object, the copy has the same format property values and includes the same format objects as the source Paragraph object. If you change a format setting in a shared format object, the source Paragraph object and the copy reflect the change. If you change a format property of the source Paragraph object or the copy, the PPT API adds a new format object to the Style property of the object that you changed. Because the source Paragraph object and the copy no longer share the same format object, the change to the format property in one of the Paragraph objects does not affect the other object.

Create an mlreportgen.ppt.Paragraph object with the Bold and Italic properties set to true.

import mlreportgen.ppt.*;
p = Paragraph("My slide content");
p.Bold = true;
p.Italic = true;

The PPT API sets the Style property of the Paragraph object to a cell array that contains an mlreportgen.ppt.Bold object with Value set to true and an mlreportgen.ppt.Italic object with Value set to true.

p.Style
ans=1×2 cell array
    {1x1 mlreportgen.ppt.Bold}    {1x1 mlreportgen.ppt.Italic}

Clone the Paragraph object. The Bold, Italic, and Style property values are the same as those of the source Paragraph object.

pClone = clone(p);
pClone.Bold
ans = logical
   1

pClone.Italic
ans = logical
   1

pClone.Style
ans=1×2 cell array
    {1x1 mlreportgen.ppt.Bold}    {1x1 mlreportgen.ppt.Italic}

In the Style property of the source Paragraph object, set the Value property of the Italic object to false. This change affects the copy of the Paragraph object because its Style property includes the same Italic object as the source Paragraph object. The PPT API sets the value of the Italic property of the Paragraph copy to false so that it matches the value of the Italic object included in the Style property.

p.Style{2}.Value = false;
pClone.Italic
ans = logical
   0

In the copy of the Paragraph object, set the Bold property to false. This change does not affect the source Paragraph object. In the source Paragraph object, the Bold property is still true.

pClone.Bold = false;
p.Bold
ans = logical
   1

Tips

  • Use the clone method to include the same paragraph content more than once in a presentation.

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

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

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

Version History

Introduced in R2021b