简体   繁体   English

PowerPoint幻灯片中的foreach图表?

[英]foreach chart in powerpoint slide ?

I have 2 questions. 我有两个问题。

1. I have VS2010 with Frameowrk 3.5 and need to lift some data and text and update some existing Powerpoint files. 1.我有带有Frameowrk 3.5的VS2010,需要提升一些数据和文本并更新一些现有的Powerpoint文件。 What would be the best approach ? 最好的方法是什么? I'm new to VSTO but have been using C# for quite a while. 我是VSTO的新手,但已经使用C#相当一段时间了。

2. I've been testing with the Interop libraries (Microsoft.Office.Interop.PowerPoint) So I need to open a powerpoint and change some text in all slides and charts. 2.我一直在使用Interop库(Microsoft.Office.Interop.PowerPoint)进行测试,因此我需要打开一个Powerpoint并更改所有幻灯片和图表中的一些文本。 Slides and sahapes are no problem but charts seem to be a problem. 幻灯片和便笺没问题,但图表似乎是个问题。 There doesn't seem to be a charts collection and if (shape.Type == Office.MsoShapeType.msoChart) returns false. 似乎没有图表集合,并且if(shape.Type == Office.MsoShapeType.msoChart)返回false。

I've done this previously in VBA and used the code below 我之前在VBA中完成了此操作,并使用了以下代码

For Each chtChart In sht.ChartObjects
        chtChart.Chart.ChartTitle.Characters.Text = Replace    (chtChart.Chart.ChartTitle.Characters.Text, "{month}", strCurrent,    VbCompareMethod.vbTextCompare)
Next chtChart

I just really want to do the same. 我只是真的想做同样的事情。

Am I missing something really obvious ? 我是否缺少某些明显的东西?

Any pointers gratefully received. 感激任何指针。

Steve 史蒂夫

There are several types of charts you might run across in PPT. 您可能会在PPT中运行几种图表类型。 Ignoring the old MSGraph charts, you might find charts that the user has added using Insert | 忽略旧的MSGraph图表,您可能会发现用户使用“插入” |“添加”添加的图表。 Chart. 图表。

These will be shapes of .Type = 3 (msoChart). 这些形状将是.Type = 3(msoChart)的形状。 Here's an example of how you get at the chart and/or chart data for these: 这是如何获取这些图表和/或图表数据的示例:

Sub ShowChartData()

Dim oSh As Shape
Dim oCht As Chart
Dim oData As ChartData

Dim x As Long
Dim y As Long
Dim sTemp As String

Set oSh = ActiveWindow.Selection.ShapeRange(1)

Set oCht = oSh.Chart
oCht.ChartData.Activate
Set oData = oCht.ChartData

For x = 1 To 4
    For y = 1 To 4
        sTemp = sTemp & oData.Workbook.Worksheets("Sheet1").Cells(x, y) & vbTab
    Next    ' y/cell
    Debug.Print sTemp
    sTemp = ""
Next ' x/row

' do this to get rid of visible worksheet
oData.Workbook.Close

Set oData = Nothing
Set oCht = Nothing

End Sub

Charts might also be linked or embedded objects copy/pasted from Excel. 图表也可能是链接的或从Excel复制/粘贴的嵌入式对象。

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

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