How to Copy Paragraph & Portion of Text in PPTX Presentation inside .NET Apps

This technical tip explains how .NET developers to copy paragraph & portion of text in PPTX presentation using Aspose.Slides inside their .NET applications. In order to format presentation text we need to format that on Paragraph and Portion level. There are some text properties that can be set on Paragraph level and some are set on Portion level. If there is a paragraph or portion in the text that we need to copy to newly added paragraphs or portions, we need to copy all properties of respective paragraph or portion to newly added paragraph or portion. The properties of the Paragraph can be accessed in ParagraphFormat instance of Pargraph class. We need to copy all the properties of source paragraph to target paragraph. In the following example, the CopyParagraph method is shared that takes paragraph to be copied as an argument. It copies all the properties of source paragraph to a temporary paragraph and return the same. The target paragraph gets the copied values.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...//Copying a Paragraph
//[C# Code Sample]
 
//Function Call
IParagraph newPara=CopyParagraph(SourcePara);
//Function Definition//Function Definition
public static IParagraph CopyParagraph(IParagraph par)
{
    Paragraph temp = new Paragraph();
    // use CreateParagraphFormatData !!!
    IParagraphFormatEffectiveData paraData = par.CreateParagraphFormatEffective();
    // use ParagraphFormat  to set values
    temp.ParagraphFormat.Alignment = paraData.Alignment;
    temp.ParagraphFormat.DefaultTabSize = paraData.DefaultTabSize;
    temp.ParagraphFormat.MarginLeft = paraData.MarginLeft;
    temp.ParagraphFormat.MarginRight = paraData.MarginRight;
    temp.ParagraphFormat.FontAlignment = paraData.FontAlignment;
    temp.ParagraphFormat.Indent = paraData.Indent;
    temp.ParagraphFormat.Depth = paraData.Depth;
    temp.ParagraphFormat.SpaceAfter = paraData.SpaceAfter;
    temp.ParagraphFormat.SpaceBefore = paraData.SpaceBefore;
    temp.ParagraphFormat.SpaceWithin = paraData.SpaceWithin;
    temp.ParagraphFormat.Bullet.Type = paraData.Bullet.Type;
    temp.ParagraphFormat.Bullet.Char = paraData.Bullet.Char;
    temp.ParagraphFormat.Bullet.Color.Color = paraData.Bullet.Color;
    temp.ParagraphFormat.Bullet.Height = paraData.Bullet.Height;
    temp.ParagraphFormat.Bullet.Font = paraData.Bullet.Font;
    temp.ParagraphFormat.Bullet.NumberedBulletStyle = paraData.Bullet.NumberedBulletStyle;
    temp.ParagraphFormat.FontAlignment = paraData.FontAlignment;
    temp.ParagraphFormat.RightToLeft = paraData.RightToLeft ? NullableBool.True : NullableBool.False;
    temp.ParagraphFormat.EastAsianLineBreak = paraData.EastAsianLineBreak ? NullableBool.True : NullableBool.False;
    temp.ParagraphFormat.HangingPunctuation = paraData.HangingPunctuation ? NullableBool.True : NullableBool.False;
    return temp;
}
public static Paragraph CopyParagraph(Paragraph par)
 
//[VB.NET Code Sample]
 
'Function Call
Dim newPara As IParagraph=CopyParagraph(SourcePara)
X

Url: http://www.aspose.com/.net/powerpoint-component.aspx

Language: C# | User: Sheraz Khan | Created: Jun 1, 2016 | Tags: Copy a Paragraph in PPTX Copy a text Portion in PPTX format presentation text copy to newly added paragraphs copy paragraph as an argument .NET PowerPoint API PowerPoint .NET Component