简体   繁体   English

以编程方式在Powerpoint演示文稿中编辑Text,Tables和Tablesproperties

[英]Programatically edit Text, Tables and Tablesproperties in a Powerpoint presentation

I must write a program that read some data from SharePoint and write it into a PowerPoint presentation. 我必须编写一个程序,该程序从SharePoint中读取一些数据并将其写入PowerPoint演示文稿中。 There are some wildcards in the presentation, like ##budget## which I must replace with the values from SharePoint. 演示文稿中有一些通配符,例如## budget ##,我必须将其替换为SharePoint中的值。 This could be done by search and replace into the PowerPoint presentation, I think. 我认为,这可以通过搜索并替换为PowerPoint演示文稿来完成。

But there are also tables which background must be colored red, green, yellow etc. and I don't know, which options there are to identify the particular tables and the affected cells and which would be the best way to do that. 但是也有一些表格,背景必须用红色,绿色,黄色等颜色填充,我不知道,有哪些选项可以识别特定的表格和受影响的单元格,而哪种方法是最好的方法。

This would work for one wildcard; 这将适用于一个通配符; you'll want to change it to either take a parameter ( the different wildcard text strings you're searching for ) or to call another routine that searches for each wildcard in turn. 您需要将其更改为采用一个参数(您要搜索的不同通配符文本字符串),或调用另一个例程依次搜索每个通配符。 But here's how you'd find text in a cell and color it as needed: 但是,这是在单元格中查找文本并根据需要为其着色的方式:

Dim oSl As Slide
Dim oSh As Shape
Dim oTbl As Table
Dim x As Long
Dim y As Long

For Each oSl In ActivePresentation.Slides
    For Each oSh In oSl.Shapes

        ' other code here to check for ## text in the shape

        If oSh.HasTable Then
            Set oTbl = oSh.Table
            With oTbl
                For x = 1 To .Rows.Count
                    For y = 1 To .Columns.Count
                        With .Cell(x, y)
                            If InStr(.Shape.TextFrame.TextRange.Text, "##budget##") > 0 Then
                                .Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
                            End If
                        End With
                    Next
                Next
            End With

        End If
    Next
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM