【问题标题】:PowerPoint Programming: Indentation with Ruler margin levels not working?PowerPoint 编程:标尺边距水平的缩进不起作用?
【发布时间】:2011-07-09 00:28:40
【问题描述】:

最近我们升级了一个 PowerPoint 插件以支持 2007 和 2010。我们能够毫无问题地移植大部分项目。我们遇到的一个问题是,使用插件创建表格或形状时,缩进不起作用。

例如:在 2003 年使用适当的缩进删除同一张表,但在使用 2007 年添加相同的东西时不会缩进。

下面是允许缩进的代码 sn-p:

With PropertyValues.ObjShape.Table.Cell(row, col).Shape.TextFrame.Ruler
               For rulerCount = 0 To 5
                    .Levels(rulerCount).FirstMargin = rulerFirstMargin(rulerCount) '.LeftMargin = rulerLeftMargin
                    .Levels(rulerCount).LeftMargin = rulerLeftMargin(rulerCount) 'Left indent marker
                Next rulerCount
        End With

知道为什么这不起作用吗?

我也阅读了以下帖子,但没有太大帮助 http://answers.microsoft.com/en-us/office/forum/office_2007-customize/why-shapetextframerulerlevelsi-cant-set-the-bullet/9eac3e46-b13b-433e-b588-216ead1d9c1a?tab=AllReplies#tabs

更新代码:

 PropertyValues.ObjShape.Table.Cell(row, col).Shape.TextFrame.TextRange.Text = "N/A"
            With PropertyValues.ObjShape.Table.Cell(row, col).Shape.TextFrame
                'Dim rulerCount As Short
                For rulerCount = 1 To 5
                    .Ruler.Levels(rulerCount).FirstMargin = 10 * rulerCount 'rulerFirstMargin(rulerCount) '.LeftMargin = rulerLeftMargin
                    .Ruler.Levels(rulerCount).LeftMargin = 20 * rulerCount 'rulerLeftMargin(rulerCount) 'Left indent marker
                Next rulerCount
            End With
            PropertyValues.ObjShape.Table.Cell(row, col).Shape.TextFrame.TextRange.Text = text

【问题讨论】:

    标签: vsto powerpoint office-interop officedev


    【解决方案1】:

    FWIW,在 2007 年及以后,您现在可以拥有多达 9 个标尺级别,而不是早期版本中的 5 个。但是您的代码应该按原样工作。这是一个简化的版本,可以在表格的任意单元格 (2,2) 上工作:

    Dim oSh As Shape
    Dim x As Long
    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    
    With oSh.Table.Cell(2, 2).Shape.TextFrame
        For x = 1 To 9
        .Ruler.Levels(x).LeftMargin = x * 10
        .Ruler.Levels(x).FirstMargin = x * 20
        Next
    End With
    

    您可能会遇到的另一件事是您可以随意应用某些类型的格式(包括标尺设置);如果你应用它的级别没有文本,PPT 就不会吠叫。它会不理你。您的设置将无效。有时您需要检查文本,如果没有则提供一些文本(在现实世界中是极不可能的),然后删除所有不可能的文本实例。

    丑陋。是的。

    这里我们在尝试格式化每个缩进级别之前添加文本并设置缩进级别:

    Sub test()
    
    Dim oSh As Shape
    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    Dim RulerCount As Long
    Dim sTemp As String
    
    sTemp = "@#$%"  ' dummy text
    
    With oSh.Table.Cell(2, 3).Shape.TextFrame
    
        For RulerCount = 1 To 5
            .TextRange.Paragraphs(RulerCount).Text = sTemp & vbCrLf
            .TextRange.Paragraphs(RulerCount).IndentLevel = RulerCount
        Next
        For RulerCount = 1 To 5
            .Ruler.Levels(RulerCount).FirstMargin = 10 * RulerCount 'rulerFirstMargin(rulerCount) '.LeftMargin = rulerLeftMargin
            .Ruler.Levels(RulerCount).LeftMargin = 20 * RulerCount 'rulerLeftMargin(rulerCount) 'Left indent marker
        Next RulerCount
    End With
    
    
    End Sub
    

    【讨论】:

    • 史蒂夫感谢您提供的线索。但请检查上面的更新代码。它也没有用。我们有什么特别要做的吗?除此之外,如果我调试并看到左边距值..它说值超出范围?但我设置值 0,36,72,108,144
    猜你喜欢
    • 1970-01-01
    • 2013-12-17
    • 2015-08-22
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多