Reputation: 174467
I am trying to read the category names of a waterfall chart in a PowerPoint VSTO project.
So far, I was unable to do so.
Here is what I tried:
chart.SeriesCollection(x).Axes(y).CategoryNames
- not available for this chart typechart.SeriesCollection(x).XValues
- not available for this chart typechart.SeriesCollection(x).Points(y).DataLabel.Text
/ .Caption
- this returns the point value, not the category name, e.g. -130chart.SeriesCollection(x).DataLabels(y).Text
/ .Caption
- same as previous: It returns the point valuesThen, I tried reading the source data directly via chart.ChartData.Workbook
but this is also not available.
So, how can I read the category names?
Upvotes: 4
Views: 482
Reputation: 3175
It appears that, as of this writing, the XlChartType enumeration is missing a member for Waterfall. (Waterfall has a ChartType
integer value of 119, which is simply missing in the enumeration.)
As the missing enumeration creates all sorts of issues, I decided to write code that would convert the chart to an enumerated type, place the Category Names into an array, and then use PowerPoint's Undo
functionality to restore the chart.
PowerPoint.Chart myChart = Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[2].Chart;
myChart.ChartType = Office.XlChartType.xlBarStacked;
PowerPoint.Axis CategoryAxis = Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[2].Chart.Axes(PowerPoint.XlAxisType.xlCategory, PowerPoint.XlAxisGroup.xlPrimary);
Array CatNames = (Array)((object)CategoryAxis.CategoryNames);
Globals.ThisAddIn.Application.CommandBars.ExecuteMso("Undo");
//Do something here with the CatNames array
Upvotes: 2