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.
//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)
'Function Definition
Public Shared Function CopyParagraph(ByVal par As IParagraph) As IParagraph
Dim temp As New Paragraph()
' use CreateParagraphFormatData !!!
Dim paraData As IParagraphFormatEffectiveData = 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 = If(paraData.RightToLeft, NullableBool.True, NullableBool.False)
temp.ParagraphFormat.EastAsianLineBreak = If(paraData.EastAsianLineBreak, NullableBool.True, NullableBool.False)
temp.ParagraphFormat.HangingPunctuation = If(paraData.HangingPunctuation, NullableBool.True, NullableBool.False)
Return temp
End Function
//Copying a PortionEx
// In the following example, the CopyPortion method is shared that takes portion to be copied as an argument. It copies all the properties of source portion to a temporary portion and return the same. The target portion gets the copied values.
//[C# Code Sample]
//Function Call
IPortion newPortion=CopyPortion(SourcePortion);
//Function Definition
public static IPortion CopyPortion(IPortion por)
{
Portion temp = new Portion();
//use CreatePortionFormatData!!!
IPortionFormatEffectiveData portData = por.CreatePortionFormatEffective();
// use PortionFormat to set values
temp.PortionFormat.AlternativeLanguageId = portData.AlternativeLanguageId;
temp.PortionFormat.BookmarkId = portData.BookmarkId;
temp.PortionFormat.Escapement = portData.Escapement;
temp.PortionFormat.FillFormat.FillType = por.PortionFormat.FillFormat.FillType;
temp.PortionFormat.FillFormat.SolidFillColor.Color = portData.FillFormat.SolidFillColor;
temp.PortionFormat.FontBold = portData.FontBold ? NullableBool.True : NullableBool.False;
temp.PortionFormat.FontHeight = portData.FontHeight;
temp.PortionFormat.FontItalic = portData.FontItalic ? NullableBool.True : NullableBool.False;
temp.PortionFormat.FontUnderline = portData.FontUnderline;
temp.PortionFormat.UnderlineFillFormat.FillType = portData.UnderlineFillFormat.FillType;
temp.PortionFormat.UnderlineFillFormat.SolidFillColor.Color = portData.UnderlineFillFormat.SolidFillColor;
temp.PortionFormat.IsHardUnderlineFill = portData.IsHardUnderlineFill ? NullableBool.True : NullableBool.False;
temp.PortionFormat.IsHardUnderlineLine = portData.IsHardUnderlineLine ? NullableBool.True : NullableBool.False;
temp.PortionFormat.KerningMinimalSize = portData.KerningMinimalSize;
temp.PortionFormat.Kumimoji = portData.Kumimoji ? NullableBool.True : NullableBool.False;
temp.PortionFormat.LanguageId = portData.LanguageId;
temp.PortionFormat.LatinFont = portData.LatinFont;
temp.PortionFormat.EastAsianFont = portData.EastAsianFont;
temp.PortionFormat.ComplexScriptFont = portData.ComplexScriptFont;
temp.PortionFormat.SymbolFont = portData.SymbolFont;
temp.PortionFormat.TextCapType = portData.TextCapType;
temp.PortionFormat.Spacing = portData.Spacing;
temp.PortionFormat.StrikethroughType = portData.StrikethroughType;
temp.PortionFormat.ProofDisabled = portData.ProofDisabled ? NullableBool.True : NullableBool.False;
temp.PortionFormat.NormaliseHeight = portData.NormaliseHeight ? NullableBool.True : NullableBool.False;
temp.PortionFormat.HyperlinkMouseOver = portData.HyperlinkMouseOver;
temp.PortionFormat.HyperlinkClick = por.PortionFormat.HyperlinkClick;
temp.PortionFormat.HighlightColor.Color = portData.HighlightColor;
return temp;
}
//[VB.NET Code Sample]
'Function Call
Private newPortion As IPortion=CopyPortion(SourcePortion)
'Function Definition
Public Shared Function CopyPortion(ByVal por As IPortion) As IPortion
Dim temp As New Portion()
'use CreatePortionFormatData!!!
Dim portData As IPortionFormatEffectiveData = por.CreatePortionFormatEffective()
' use PortionFormat to set values
temp.PortionFormat.AlternativeLanguageId = portData.AlternativeLanguageId
temp.PortionFormat.BookmarkId = portData.BookmarkId
temp.PortionFormat.Escapement = portData.Escapement
temp.PortionFormat.FillFormat.FillType = por.PortionFormat.FillFormat.FillType
temp.PortionFormat.FillFormat.SolidFillColor.Color = portData.FillFormat.SolidFillColor
temp.PortionFormat.FontBold = If(portData.FontBold, NullableBool.True, NullableBool.False)
temp.PortionFormat.FontHeight = portData.FontHeight
temp.PortionFormat.FontItalic = If(portData.FontItalic, NullableBool.True, NullableBool.False)
temp.PortionFormat.FontUnderline = portData.FontUnderline
temp.PortionFormat.UnderlineFillFormat.FillType = portData.UnderlineFillFormat.FillType
temp.PortionFormat.UnderlineFillFormat.SolidFillColor.Color = portData.UnderlineFillFormat.SolidFillColor
temp.PortionFormat.IsHardUnderlineFill = If(portData.IsHardUnderlineFill, NullableBool.True, NullableBool.False)
temp.PortionFormat.IsHardUnderlineLine = If(portData.IsHardUnderlineLine, NullableBool.True, NullableBool.False)
temp.PortionFormat.KerningMinimalSize = portData.KerningMinimalSize
temp.PortionFormat.Kumimoji = If(portData.Kumimoji, NullableBool.True, NullableBool.False)
temp.PortionFormat.LanguageId = portData.LanguageId
temp.PortionFormat.LatinFont = portData.LatinFont
temp.PortionFormat.EastAsianFont = portData.EastAsianFont
temp.PortionFormat.ComplexScriptFont = portData.ComplexScriptFont
temp.PortionFormat.SymbolFont = portData.SymbolFont
temp.PortionFormat.TextCapType = portData.TextCapType
temp.PortionFormat.Spacing = portData.Spacing
temp.PortionFormat.StrikethroughType = portData.StrikethroughType
temp.PortionFormat.ProofDisabled = If(portData.ProofDisabled, NullableBool.True, NullableBool.False)
temp.PortionFormat.NormaliseHeight = If(portData.NormaliseHeight, NullableBool.True, NullableBool.False)
temp.PortionFormat.HyperlinkMouseOver = portData.HyperlinkMouseOver
temp.PortionFormat.HyperlinkClick = por.PortionFormat.HyperlinkClick
temp.PortionFormat.HighlightColor.Color = portData.HighlightColor
Return temp
End Function
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