none
Find all superscripts used in the PowerPoint slide RRS feed

  • Question

  • I am using PowerPoint VSTO with C#.

    Is there any way to find all superscripts from PowerPoint slide?

    I have tried Font.Superscript property but it only works if we know the range of superscript word.

    Thursday, April 20, 2017 9:26 AM

All replies

  • Hi Saurabh Singh Jadon,

    I try to make search regarding c# example but did not get anything.

    I have example in VBA. you can try to convert it to C#.

    Sub demo()
    
    Dim oSl As Slide
    Dim oSh As Shape
    Dim x As Long
    Dim dBumpBy As Double
    
    dBumpBy = 4 ' number of points to bump sub/superscript by
    ' Check each slide
    For Each oSl In ActivePresentation.Slides
      ' Check each shape on the slide
      For Each oSh In oSl.Shapes
        ' Make sure it's got text
        If oSh.HasTextFrame Then
          If oSh.TextFrame.HasText Then
            With oSh.TextFrame.TextRange
              For x = 1 To .Runs.Count
                If .Runs(x).Characters.Font.BaselineOffset <> 0 Then
                ' it's a sub/super; make it four points
                ' bigger than the text immediately prior:
                .Runs(x).Characters.Font.Size = _
                   .Runs(x - 1).Characters.Font.Size + dBumpBy
                   MsgBox (.Runs(x).Characters.Text)
            End If  ' it's a sub/superscript
          Next x
        End With    ' textframe.textrange
          End If    '  .HasText
        End If  '  .HasTextFrame
      Next oSh      '
    Next oSl
    
    End Sub

    I try to convert it to C# but not working correctly.

     private void button1_Click(object sender, EventArgs e)
            {
                
                var app = new PowerPoint.Application();
    
                var pres = app.Presentations;
                PowerPoint.Presentation pp;
               
    
                pp = pres.Open(@"C:\Users\v-padee\Desktop\demop.pptm", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
                app.Visible = MsoTriState.msoTrue;
    
    
                foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in pp.Slides)
                {
                    foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
                    {
                        if(shape.HasTextFrame==MsoTriState.msoTrue)
                        {
                            var _with1 = shape.TextFrame.TextRange;
                            for (int k = 0; k < _with1.Count; k++)
                            {
                                MessageBox.Show(shape.TextFrame.TextRange.Runs(k).Characters().Font.BaselineOffset.ToString());
                                if (shape.TextFrame.TextRange.Runs().Characters().Font.BaselineOffset != 0)
                                {
                                    MessageBox.Show(shape.TextFrame.TextRange.Runs(k).Text);
                                }
                             
                            }
    
                        }
                    }
                    
                }
    
               
            }

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 21, 2017 3:20 AM
    Moderator
  • Ok Thanks Deepak.

    I think it checks superscript on each character. It may degrade the performance.

    but I am looking for a method which gives the colooection of all superscript.

    Monday, April 24, 2017 5:25 AM
  • Hi Saurabh Singh Jadon,

    there is no property available in Powerpoint object model that can return collection of Superscript words.

    you can also refer the object model.

    Object model (PowerPoint VBA reference)

    so you have to use loop. currently there is no other way available.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 24, 2017 9:46 AM
    Moderator
  • Ok Thanks
    Wednesday, April 26, 2017 5:53 AM