我正在尝试更改 PowerPoint 中直方图图表标题的文本颜色。
这是我所做的:
var colorFormat = chart.ChartTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor;
colorFormat.RGB = ...;
// or
colorFormat.ObjectThemeColor = ...;
这适用于折线图等标准图表。但它不适用于其他图表类型,如直方图、瀑布图、树形图等。
在这些情况下,设置ObjectThemeColor
会将文本设置为黑色。设置 RGB 实际上设置了正确的颜色。但是,在这两种情况下,一旦用户更改选择,文本颜色就会跳回之前的颜色。
如何设置这些图表之一的标题文本颜色?
我使用的是 VSTO 和 C#,但 VBA 解决方案同样受欢迎,只要它可以转换为 C# 并且仍然有效。
最佳答案
根据您提供的信息,我在 PowerPoint 中构建了直方图和瀑布图,并成功使用:
Sub ChartTitleFontColor()
Dim oShp As Shape
Dim oCht As Chart
'Waterfall on slide 1
Set oShp = ActivePresentation.Slides(1).Shapes(1)
If oShp.HasChart Then
Set oCht = oShp.Chart
End If
' Do stuff with your chart
If oCht.HasTitle Then
Debug.Print oCht.ChartTitle.Text
oCht.ChartTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(251, 5, 40)
End If
'Histogram on slide 2
Set oShp = ActivePresentation.Slides(2).Shapes(1)
If oShp.HasChart Then
Set oCht = oShp.Chart
End If
' Do stuff with your chart
If oCht.HasTitle Then Debug.Print oCht.ChartTitle.Text
oCht.ChartTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(251, 5, 40)
End If
' Clean up
Set oShp = Nothing
Set oCht = Nothing
End Sub
关于vba - 更改 PowerPoint 直方图中图表标题的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49465151/