Bullet indents in PowerPoint 2007 compatibility mode via .NET interop issue

Posted by L. Shaydariv on Stack Overflow See other posts from Stack Overflow or by L. Shaydariv
Published on 2010-02-01T13:08:57Z Indexed on 2010/04/24 22:33 UTC
Read the original article Hit count: 354

Filed under:
|
|
|
|

Hello.

I've got a really difficult bug and I can't see the fix. The subject drives me insane for real for a long time. Let's consider the following scenario:

1) There is a PowerPoint 2003 presentation. It contains the only slide and the only shape, but the shape contains a text frame including a bulleted list with a random textual representation structure.

2) There is a requirement to get bullet indents for every bulletted paragraph using PowerPoint 2007. I can satisfy the requirement opening the presentation in the compatibility mode and applying the following VBA script:

With ActivePresentation
  Dim sl As Slide: Set sl = .Slides(1)
  Dim sh As Shape: Set sh = sl.Shapes(1)
  Dim i As Integer
  For i = 1 To sh.TextFrame.TextRange.Paragraphs.Count
    Dim para As TextRange: Set para = sh.TextFrame.TextRange.Paragraphs(i, 1)
    Debug.Print para.Text; para.indentLevel, sh.TextFrame.Ruler.Levels(para.indentLevel).FirstMargin
  Next i
End With

that produces the following output:

A 1 0 
B 1 0 
C 2 24 
D 3 60 
E 5 132 

Obviously, everything is perfect indeed: it has shown the proper list item text, list item level and its bullet indent. But I can't see the way of how I can reach the same result using C#. Let's add a COM-reference to Microsoft.Office.Interop.PowerPoint 2.9.0.0 (taken from MSPPT.OLB, MS Office 12):

// presentation = ...("presentation.ppt")... // a PowerPoint 2003 presentation
Slide slide = presentation.Slides[1];
Shape shape = slide.Shapes[1];
for (int i = 1; i<=shape.TextFrame.TextRange.Paragraphs(-1, -1).Count; i++) {
    TextRange paragraph = shape.TextFrame.TextRange.Paragraphs(i, 1);
    Console.WriteLine("{0} {1} {2}", paragraph.Text, paragraph.IndentLevel, shape.TextFrame.Ruler.Levels[paragraph.IndentLevel].FirstMargin);
}

Oh, man... What's it? I've got problems here. First, the paragraph.Text value is trimmed until the '\r' character is found (however paragraph.Text[0] really returns the first character O_o). But it's ok, I can shut my eyes to this. But... But, second, I can't understand why the first margins are always zero and it does not matter which level they belong to. They are always zero in the compatibility mode... It's hard to believe it... :) So is there any way to fix it or just to find a workaround? I'd like to accept any help regarding to the solution of the subject. I can't even find any article related to the issue. :( Probably you have ever been face to face with it... Or is it just a bug with no fix and must it be reported to Microsoft?

Thanks you.

© Stack Overflow or respective owner

Related posts about ms-office

Related posts about .NET