We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replacing TextFrame.Text

I am using Powerpoint 2007 and am using Aspose.Slides.Pptx. Version of DLL is 4.1.1.0

I want to replace the content within text frames in a slide dynamically with some input text at run time. For example, with a text frame, I might have a line like:
"This report is ran on @@footnote_asOfDate"
I might want to replace @@footnote_asOfDate with “December 31, 2009”.

So I call a method:
ReplaceTextFrameContent(textFrame, @@footnote_asOfDate, “December 31, 2009”)
But I found that as I loop through TextFrameEx.Paragragphs.Portions.Text,
each loop detects (or matches): @, @, footnote_asOfDate and failed to detect the special marker
@@footnote_asOfDate in its entirety.
Using a special marker like, @footnote_asOfDate@, gave me similar problems.

Another problem I found is if I have a line like this:
"Amount is $@@numberInBillions billion in revenue"
If I am successful replacing the @@numberInBillions marker by a number, the space immediately following the marker is deleted so the result is:
“Amount is 8billion in revenue”.

How should I build my special marker? Are there special symbols I should avoid?
What are the rules I need to follow?

The method ReplaceTextFrameContent(…), I have is below:

Public Shared Sub ReplaceTextFrameContent(ByVal ptf As TextFrameEx, ByVal pstrPattern As String, ByVal pnewText As String)
For Each para As ParagraphEx In ptf.Paragraphs
For Each port As PortionEx In para.Portions
If port.Text.Contains(pstrPattern) Then
port.Text = port.Text.Replace(pstrPattern, pnewText)
End If
Next
Next
End Sub


It is not clear how a paragraph is split in to portions.
Sometimes a line like:
"This report is ran on @@footnote_asOfDate"
would have portions like:
“This report is ran on @@”
“footnote_asOfDate”.

I do not have this problem on all the slides.
Some other slides I use slightly different markers like this line below:
Slide 1
.O
{color:black;
font-size:149%;}
a:link
{color:#BE6F20 !important;}
a:active
{color:#336699 !important;}
a:visited
{color:#990000 !important;}

<o:shapelayout v:ext=“edit”></o:shapelayout><o:idmap v:ext=“edit” data=“1”></o:idmap><p:colorscheme colors="#ffffff,#000000,#b2b2b2,#808080,#94b735,#336699,#be6f20,#990000">

"As of @@as_of_date"
and this line would work fine and the marker would get replaced without problems.

</p:colorscheme>

Hi,

I have worked on the problem specified by you. Actually, the text remain in a single portion as long as the font related properties are not changed in the respective paragraph. So, when some font related properties like font color, size, family and other properties are changed then the portion will get separate. I have shared the presentation file where by you may access the desired string from "This report is ran on @@footnote_asOfDate" on portion level. If you may please change font color of "@@footnote_asOfDate" or make the said string bold, then you will abe able to access the desired string. As a work around, change the font color of target string pattern and save the presentation. Again open the same presentation and restore the old color of the target string pattern. You will observe the text in separate portions. For your kind reference, the code snippet is attached as well.

Dim pres As Aspose.Slides.Pptx.PresentationEx

Dim pptxFile As String = "D:/ppt/Test_TextFrame.pptx"

Dim outputFile As String = "D:/ppt/TextFrame_output.pptx"

pres = New Aspose.Slides.Pptx.PresentationEx(pptxFile)

For Each sl As SlideEx In pres.Slides

For Each sh As ShapeEx In sl.Shapes

If sh.AlternativeText.Length > 0 Then

Dim txFrame As TextFrameEx = CType(sh, AutoShapeEx).TextFrame

For Each Para As ParagraphEx In txFrame.Paragraphs

For Each Portion As PortionEx In Para.Portions

If Portion.Text.Contains("@@TotaSalesInBillions") Then

Portion.Text = Portion.Text.Replace("@@TotaSalesInBillions", "10.0")

ElseIf Portion.Text.Contains("@@footnote_asOfDate") Then

Portion.Text = Portion.Text.Replace("@@footnote_asOfDate", "December 31, 2009")

End If

Next

Next

End If

Next

Next

pres.Write(outputFile)

Thanks and Regards,

You must be right.

I see the whole line in the Text Frame in my slide having the same format but anyway I erase the whole line and retyped the text and problem went away.

Thanks very much!