Frederik Hansen
Frederik Hansen

Reputation: 506

Creating a Map Chart in VSTO PowerPoint

I'm trying to add a map chart in PowerPoint.

As of now I can't see the option to do so in XlChartType, but if I insert one manually I can then examine the inserted chart and see that its XlChartType evaluates to 140.

If I try to insert a chart with this type I get a map chart as expected. However, if I try to access its workbook it throws an exception. These two lines of code should explain what I'm doing:

var chart = _slide.Shapes.AddChart((XlChartType)140).Chart;
var workbook = (Workbook)chart.ChartData.Workbook;

I assume this is related to the fact that it's not officially supported. Is there any way to work around this problem and edit the data of the chart?

Upvotes: 8

Views: 195

Answers (1)

Dipen Shah
Dipen Shah

Reputation: 26075

I think you are missing call to Activate method.

Checkout remark from official source:

Note You must call the Activate method before referencing this property; otherwise, an error occurs.

Your code should be:

var chart = _slide.Shapes.AddChart((XlChartType)140).Chart;
chart.ChartData.Activate(); // missing piece
var workbook = (Workbook)chart.ChartData.Workbook;

Upvotes: 4

Related Questions