Clayton Hall
Clayton Hall

Reputation: 181

How to control hanging indents using the PowerPoint API?

I am programatically creating a PowerPoint 2007 presentation in C#, but when I add the text, the second line is indented. From the UI, I would set it by going to Home->Paragraph->Indentation and setting "Before Text" to "0" and Special to "(none)". How can I accomplish the same thing programatically?

        PowerPoint.Application app = new PowerPoint.Application();
        PowerPoint.Presentation p = app.Presentations.Add(Office.MsoTriState.msoTrue);
        app.Visible = Office.MsoTriState.msoTrue;

        PowerPoint.CustomLayout customLayout = p.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutText];

        PowerPoint.Slide slide = p.Slides.AddSlide(p.Slides.Count + 1, customLayout);
        PowerPoint.Shape textShape = slide.Shapes[2];

        textShape.TextFrame.TextRange.ParagraphFormat.Bullet.Type = PowerPoint.PpBulletType.ppBulletNone;
        PowerPoint.TextRange range1 = textShape.TextFrame.TextRange.InsertAfter(@"Just enough text so that wrapping occurs.");
        range1.Font.Size = 54;

        p.SaveAs(@"c:\temp\test1.pptx", PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Office.MsoTriState.msoTrue);
        p.Close();
        app.Quit();

So... how do I ditch the hanging indent?

Upvotes: 2

Views: 1914

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 3528

In PPT 2007 and up, work with the shape's TextFrame2.Textrange.Paragraphs(x).ParagraphFormat properties. .LeftIndent gives you the overall indent for the paragraph, .FirstLineIndent gives you the indent for the first line (and it's relative to the .LeftIndent value)

Upvotes: 2

Related Questions