none
使用PowerPoint对象模型如何获取段落的缩进值 RRS feed

  • 问题

  • 你好!ParagraphFormat类提供了对行前、行后、行之间距离的属性。找遍了ParagraphFormat类,都未发现与缩进有关的属性、方法。请问,怎样才能到获取段落的缩进值呢?
    2014年10月30日 11:19

答案

  • 你好:

    请参考以下代码,获取每一个段落的缩进等级:

    Application app = new Application();
                app.Visible = MsoTriState.msoTrue;
                Presentation presentation = app.Presentations.Open(@"C:\temp\test.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
    
    
                Slide slide = presentation.Slides[1];
    
                foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
                {
                        var paragraphs = shape.TextFrame.TextRange.Paragraphs(-1, -1);
                        foreach (TextRange paragraph in paragraphs)
                        {
                            Console.WriteLine(paragraph.Text);
                            Console.WriteLine("IndentLevel:"+paragraph.IndentLevel);
                        }
                }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 wtw_Kevin 2014年11月3日 10:19
    2014年10月31日 1:59
    版主

全部回复

  • 你好:

    请参考以下代码,获取每一个段落的缩进等级:

    Application app = new Application();
                app.Visible = MsoTriState.msoTrue;
                Presentation presentation = app.Presentations.Open(@"C:\temp\test.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
    
    
                Slide slide = presentation.Slides[1];
    
                foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
                {
                        var paragraphs = shape.TextFrame.TextRange.Paragraphs(-1, -1);
                        foreach (TextRange paragraph in paragraphs)
                        {
                            Console.WriteLine(paragraph.Text);
                            Console.WriteLine("IndentLevel:"+paragraph.IndentLevel);
                        }
                }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 wtw_Kevin 2014年11月3日 10:19
    2014年10月31日 1:59
    版主
  • 很有帮助,谢谢!那能获取到具体的缩进值吗?
    2014年10月31日 4:02
  • var fm=paragraph.Parent.Ruler.Levels(2).FirstMargin;

    这可以获取到具体的缩进值。具体参考MSDN文档:

    http://msdn.microsoft.com/en-us/library/office/jj228768(v=office.15).aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年10月31日 5:22
    版主
  • 我试了下,但是FirstMargin获取的值好像不对。

    比如一个文本框,只有一个段落,段落采用默认格式,缩进级别为1,且未添加项目符号,但FirstMargn = 36.0

    2014年11月1日 3:31