论坛: 帮助论坛 (Thread #40039)

Chart adaption behaves differently with Office 2013 and 2016 (2018-10-12 21:09 by hjphilippi #82032)

Hi there,

I've created some sort of Excel template file with a bar chart object that is linked to a data table on the same worksheet. Within a .NET assembly (written in C#), I'm using NetOffice to inject the actual data into this template and adapt the chart series to only display bars where I have values. The chart adaption code looks something like this:

SeriesCollection seriesCollection = (SeriesCollection)chart.SeriesCollection();

Series seriesA = seriesCollection[1];
seriesA.Name = ... (Some string handling pointing to the series title cell)
seriesA.Values = ... (Some string handling pointing to the series data range)
seriesA.XValues = ... (Some string handling pointing to the series x-axis)

Series seriesB = seriesCollection[2];
seriesB.Name = ... (Some string handling pointing to the series title cell)
seriesB.Values = (Some string handling pointing to the series data range)
seriesB.XValues = ... (Some string handling pointing to the series x-axis)

This all works fine with Office 2013 and the chart displays 2 bars next to each other for each x-axis entry. But with Office 2016 installed, it doesn't - the first series is okay but the second one does only display its first bar, no further values.
Looking at the resulting chart data reference in the manipulated Excel file, I see that the assigned "Values" Range of the second series does not match what I have set by code. Indeed, it just points to a single cell, not a range of multiple values. When I adapt it manually, the chart is correct again, showing all values of both series like in Office 2013.

I would assume that there was some wrong string assignment or so in my C# code, but as I've said before: with Office 2013, the result is good, with Office 2016 it is not.
Do you have any idea, where the reason for this misbehavior could be found? And perhaps a possible workaround? Your help is greatly appreciated!

Best regards,
Hans