Free Support Forum - aspose.com

Shapes- TextFrames and placeholders

Hi,

Sorry to bring this old issue up again…

I have a program that iterates all shapes looking for text to perform Find/Replace operations on. This seems to work fine. However it is missing some objects, these are placeholders.

My program detects these Shapes and sure enought the text is not in the shape. However I can not seem to iterate over the placeholders (the placeholders contain text I need to adjust)

I have checked through the forum and found the 2 threads below, but they don’t seem to offer the answer.
https://forum.aspose.com/t/111163
https://forum.aspose.com/t/111163

I would rather I didn’t have to re-iterate over the placeholders, the posts above mention that all placeholders are to be merged into the shapes collection, which obviously makes my situation easier, however this hasen’t happened yet.

Also, I can’t iterate the placeholders with a For Each [PlaceHolder Object] in Slide.Placeholders loop (VB codebehind). It says its not a legal typecast.

First question, can you provide example of a placeholder typecast that will allow access to the textframe, if there is one for the placeholder?

Second, is there a way to iterate the placeholders?

Third, How would you recommend I deal with the placeholders? Ideally I would like to ‘marry’ the shape (when I iterate over it) with the placeholder, so as to access the text. THis I can’t do, any ideas?

Thanks for taking the time to look at this issue again!

Regards,

ZuluWarrior

Small VB example how to iterate placeholders.

Dim i As Integer
For i = 0 To slide.Placeholders.Count - 1
Dim holder As Placeholder = slide.Placeholders(i)
If TypeOf holder Is TextHolder Then
Dim th As TextHolder
th = CType(holder, TextHolder)
th.Paragraphs …

End If
Next

When you iterate Shapes you should check Shape.IsTextHolder property and skip
shape if this property is true.

This doesn’t always work. Create a slide whose layout contains a textbox, and enter text into it. Then change the slide layout to one that doesn’t have a default textbox. The textbox will still exist, but no longer has a placeholder. However, it still is flagged with IsTextHolder = true.

Is there a reason there isn’t a property to reference the textholder from the textframe?

I’m also running into this problem.

I had a previous problem that i fixed by stringing portions together until i found the string i was looking for, but that was fixed for everything involved that was a TextHolder.

If something is in a TextBox in powerpoint, it isn’t showing up as a textholder, as the above VB code would suggest. Instead, it’s coming up as a Rectangle at all times and never shows up as a TextFrame like the Wiki explains.

Any text that is in a textbox in powerpoint, my aspose cannot read it for some reason. Any idea why? anyone?

Thanks,
Sean Mahoney

Hi everyone,

as I am registered to this post and I can see that this issue still calls up problems, I thought it best to post the code that gave me my solution.

To re-iterate, we need to ‘touch’ every shape and placeholder, check the alternatinve text for the TEXTREPLACE key, and access the text.

To achive this, taking into account all the above advise and advise from other threads, I did this. First the code, 3 functions:

TextReplace - Iterates each paragraph and portion (in a Paragraphs object) performing text replacements (Note: I believe it is the font styles changing that prompts the start of a new portion, so unless they change mid word you should not miss any words or charecters)
Private Sub TextReplace(ByRef pars As Paragraphs)
Dim par As Paragraph, por As Portion, curFRobj As FRObj
'gotta deal with format split strings as well

For Each par In pars
For Each por In par.Portions
For Each curFRobj In FRs
Try
por.Text = por.Text.Replace(curFRobj.FindStr, curFRobj.ReplaceObj)
Catch ex As Exception
'handle replace error here
End Try
Next
Next
Next

End Sub

ProcessPH - recurces all the placeholders on a slide and calls TextReplace on the Paragraphs object of the placeholder.
Private Sub ProcessPH(ByRef sld As Slide)
Dim i As Integer

For i = 0 To sld.Placeholders.Count - 1
Dim holder As Placeholder = sld.Placeholders(i)
If TypeOf holder Is TextHolder Then
Dim th As TextHolder
th = CType(holder, TextHolder)
If Left(th.AlternativeText, 11).CompareTo(“TEXTREPLACE”) = 0 Then
TextReplace(th.Paragraphs)
End If
End If
Next

End Sub

ProcessSlide - recurces all the placeholders on a slide and calls TextReplace on the Paragraphs object of the placeholder.
Private Sub ProcessSlide(ByRef Sld As Slide)
Dim CurShp As Shape

'iterate each shape on the slide and process as type
For Each CurShp In Sld.Shapes
If Not CurShp.IsTextHolder Then
If Left(CurShp.AlternativeText, 11).CompareTo(“TEXTREPLACE”) = 0 Then
TextReplace(CurShp.TextFrame.Paragraphs)
End If
End If
Next

End Sub

What I do is iterate each Slide master, and call ProcessSlide on each, then itterate all the slides in the Slides collection of the Powerpoint object, calling both ProcessSlide and ProcessPH on each. I find this covers all the objects. Please note that in the TextReplace routine there is an object called curFRobj that contains both the word to find and the word to replace.

I hope this helps some of you guys!

Regards,

ZuluWarrior