Hi,support:
Is there any way to get the font size and text of each textbox/shape based on Vb.net?
Thanks for your help!
Hi,support:
Is there any way to get the font size and text of each textbox/shape based on Vb.net?
Thanks for your help!
Please consider using following example on your end.
Public Shared Sub ExtractFontInfo()
Dim pres As Presentation = New Presentation("Test.pptx")
For Each slide As ISlide In pres.Slides
For Each shape As IShape In slide.Shapes
If TypeOf shape Is IAutoShape Then
Dim ashp As IAutoShape = CType(shape, IAutoShape)
If ashp.TextFrame IsNot Nothing Then
Dim textFrame As ITextFrame = ashp.TextFrame
For Each para As IParagraph In textFrame.Paragraphs
For Each portion As IPortion In para.Portions
Console.WriteLine("Text is: " & portion.Text)
If portion.PortionFormat IsNot Nothing Then
Console.WriteLine("Font Size: " & portion.PortionFormat.FontHeight)
Console.WriteLine("Font Name: " & portion.PortionFormat.LatinFont.FontName)
End If
Next
Next
End If
End If
Next
Next
End Sub
Thanks for your reply.
But this still fail to get the text from textboxes because two reasons:
Please provide a working sample project along with source file on your end. However, before executing following line, you need to check first if the shape that you are trying to typecast is actually an AutoShape or not.
if the shape is a picture frame, when executing Dim ashp As IAutoShape = CType(shape, IAutoShape),it will throw exception.
This is programming error as you are trying to typecast a different shape to some other shape object. Therefore, I shared that you need to verify the shape type before typecasting the shape object to some shape.