Free Support Forum -

Why does Aspose change the font size & spacing when I update TextFrame.Text?

I marked up a rectangular shape of text to be updated by inserting some marker text in the Alternative Text. I loop thru all my slides and shapes. When I find my shape, I replace the TextFrame.Text with my desired new text. Everything works and the text got changed to what I want except that Aspose unexpectedly modified the font size, color and spacing, etc. If users just change the TextFrame.Text, they do not expect the font size or other styles to be changed. Below is the few lines of code I have. Why does Aspose change the font size & styles? Did I do anything wrong or could there be potentially be a bug somewhere?

To partially fixed the problem, I had to changed the font size back to the original value before the update, by adding these two lines:

pshape.TextFrame.Paragraphs(0).Portions(0).FontHeight = 7

pshape.TextFrame.Paragraphs(1).Portions(0).FontHeight = 7

This is the code:

' loop thru each slide and each shape in a slide and change the text
Private Sub updateSlides(ByVal pres As Presentation)
For Each sl As Slide In pres.Slides
For Each sh As Shape In sl.Shapes
If sh.AlternativeText = "update_text" Then
End If
End Sub


' replace the special marker within the TextFrame with desired new text
Private Sub updateText(ByVal pshape As Shape, ByVal QuarterEndDate as DateTime)
Dim textContent As String = pshape.TextFrame.Text
If textContent.Contains("@@as_of_date") Then
pshape.TextFrame.Text = pshape.TextFrame.Text.Replace("@@as_of_date", Format(QuarterEndDate, "MMMM d, yyyy"))

' I should not need these following lines to change the font size back to the original value

pshape.TextFrame.Paragrahps(0).FontHeight = 7

pshape.TextFrame.Paragrahps(0).FontHeight = 7

End If
End Sub

By the way, wouldn't it nice if Aspose would provide some facility or feature that allows me to put in smart marker so I can easily do search-and-replace. As you know Aspose.Cells has the smart markers (Designer Template) feature that I love.

The code I have in the previous posting is my manual cheap way of giving my myself this search-and-replace feature.

It would think it is possible for Aspose to provide a wonderful feature like this. Your customers would love a feature like this!!


Actuall formatting is present inside the Portion object, so if you will change the text using the TextFrame.Text property, it will override the actual formatting with default formatting.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

So, you should change text at the Portion level eg

tf.Paragraphs(0).Portions(0).Text=”This text will not lose formatting”;

You can also find shape with alternative text with this way, in your code

Dim sh as Shape=sl.FindShape("update_text")

I experimented with your suggestion but ran into an exception. It appears that if there area already line returns in the tf.Paragraphs(0).Portions(0).Text, then I cannot update the text by doing:

tf.Paragraphs(0).Portions(0).Text=”This can cause an exception”

The exception I got is: Aspose.Slides.PptException: Can't assign string which contains paragraph break character

The excerpt of my code is this:

If textContent.Contains("@@benchmark_download_date") Then
Line 668: Dim bechmarkDownloadDate As Date = getBenchmarkDataDownloadDate(Me.QuarterEndDate, Me.DataVersionId)
sh.TextFrame.Paragraphs(0).Portions(0).Text = sh.TextFrame.Text.Replace("@@benchmark_download_date", Format(bechmarkDownloadDate, "MMMM d, yyyy"))

You can use the following method to replace the text with line feeds or carriage return.

It automatically split the text and add them as separate paragraphs.



Public Sub SetText(ByVal tf As TextFrame, ByVal text As String)

'Split on the basis of carriage return and line feed

Dim _split() As String

_split = text.Split(New Char() {vbCr, vbLf})

Dim idx As Integer

Dim para As Paragraph

para = Nothing

For Each txt As String In _split

'Don't let empty text enter

'change it into space

If txt = "" Then

txt = " "

End If

'Get the paragraph and set its text

para = tf.Paragraphs(idx)

para.Portions(0).Text = txt

'Add new one

para = New Paragraph(para)


'increment idx

idx = idx + 1


If idx > 0 Then


End If

End Sub