Best Method for reading/updating text of a rectangle shape/placeholder?

According to the posting here:
http://www.aspose.com/Community/Forums/46238/ShowPost.aspx

“All Rectangles have property IsTextHolder set to true so these
shapes should be changed as Placeholders”

This is great, but what happens if the rectangle shape does not have a corresponding entry in the placeholders collection.

In my attached sample- presentation and code to read the ppt slide properties, there are two rectangle shapes and only one placeholder.

My code reads the text on a slide and does some text replacement. My algorithm is based on the code here:
http://www.aspose.com/Community/Forums/26200/ShowPost.aspx

Basically, the intent I believe is to see if the shape is really a placeholder and then access it as a placeholder instead.

The problem I have is that this logic doesn’t work for the attached example.

Any thoughts?

Phil

Dear Phil,

Is this presentation created with Aspose.Slides or with MS PowerPoint?
If you didn’t use Aspose.Slides to change it then I should tell thank you very much for this example.
It’s a first presentation where text of placeholder located in the shape’s instead of placeholder’s record.

Sorry, I didn’t answer your question.
If shape is a placeholder and has some text inside then you can change text directly in the shape.

This sample was created directly through Powerpoint. I believe all that I did was create a new slide with layout "title and text", enter some text into the place holders, and then change the layout to "title only".

So... according to your last post, there is no harm in changing text of a shape that is a placeholder, I just need to go through the place holders too?

my original algorithm is:

Replace tokens on a slide:

For Each shape As Aspose.Slides.Shape In slide.Shapes
ReplaceTokensInShape(shape)
Next

For i As System.Int32 = 0 To slide.Placeholders.Count - 1
Dim holder As Aspose.Slides.Placeholder = slide.Placeholders(i)
If holder.GetType.Equals(GetType(Aspose.Slides.TextHolder)) Then
Dim textHolder As Aspose.Slides.TextHolder = DirectCast(holder, Aspose.Slides.TextHolder)
ReplaceTokensInParagraphs(textHolder.Paragraphs)
End If
Next

Public Shared Sub ReplaceTokensInShape(ByVal shape As Aspose.Slides.Shape)
If shape.GetType.Equals(GetType(Aspose.Slides.GroupShape)) Then
Dim groupShape As Aspose.Slides.GroupShape = DirectCast(shape, Aspose.Slides.GroupShape)
For Each shapeInGroup As Aspose.Slides.Shape In groupShape.Shapes
ReplaceTokensInShape(shapeInGroup)
Next
ElseIf shape.GetType.Equals(GetType(Aspose.Slides.Table)) Then
Dim tableShape As Aspose.Slides.Table = DirectCast(shape, Aspose.Slides.Table)
For Each shapeInGroup As Aspose.Slides.Shape In tableShape.Shapes
ReplaceTokensInShape(shapeInGroup)
Next
ElseIf Not shape.IsTextHolder AndAlso Not shape.TextFrame Is Nothing Then
ReplaceTokensInParagraphs(shape.TextFrame.Paragraphs)
End If
End Sub

I have bolded the place where the logic fails because the placeholder/shape has IsTextHolder = True so it never calls ReplaceTokensInParagraphs.

If I understand what you're saying I can remove this part of the if clause....

Does that sound correct? I'm sorry to give you all this VB code.....so, I can access the text of a placeholder through the shape object or through the placeholder object (assuming it exists)....

Phil

Simply delete bolded text is not right way.
You can change text directly in the shape if textholder doesn’t exist only.
If textholder exists and you change text in the shape then ppt file can become broken.

Ok. so is there are work around to this that I can do? How could I tell if a shape with isTextHolder=true is not contained in the placeholders collection? Sorry to be dense about this, it's just something I want to get right.

Thank you for all your help.

Phil

I'd suggest something like this.

Dim holderShapes As Hashtable = New HashTable()
For i As System.Int32 = 0 To slide.Placeholders.Count - 1
Dim holder As Aspose.Slides.Placeholder = slide.Placeholders(i)
If holder.GetType.Equals(GetType(Aspose.Slides.TextHolder)) Then
Dim textHolder As Aspose.Slides.TextHolder = DirectCast(holder, Aspose.Slides.TextHolder)
holderShapes.Item(textHolder.ShapeRef) = Nothing
ReplaceTokensInParagraphs(textHolder.Paragraphs)
End If
Next

For Each shape As Aspose.Slides.Shape In slide.Shapes
ReplaceTokensInShape(shape, holderShapes)
Next

Public Shared Sub ReplaceTokensInShape(ByVal shape As Aspose.Slides.Shape, ByVal holders As Hashtable)
If shape.GetType.Equals(GetType(Aspose.Slides.GroupShape)) Then
Dim groupShape As Aspose.Slides.GroupShape = DirectCast(shape, Aspose.Slides.GroupShape)
For Each shapeInGroup As Aspose.Slides.Shape In groupShape.Shapes
ReplaceTokensInShape(shapeInGroup)
Next
ElseIf shape.GetType.Equals(GetType(Aspose.Slides.Table)) Then
Dim tableShape As Aspose.Slides.Table = DirectCast(shape, Aspose.Slides.Table)
For Each shapeInGroup As Aspose.Slides.Shape In tableShape.Shapes
ReplaceTokensInShape(shapeInGroup)
Next
ElseIf Not shape.IsTextHolder AndAlso Not shape.TextFrame Is Nothing Then
ReplaceTokensInParagraphs(shape.TextFrame.Paragraphs)
ElseIf shape.IsTextHolder And Not holders.ContainsKey(shape) Then
ReplaceTokensInParagraphs(shape.TextFrame.Paragraphs)
End If
End Sub