Excel chart trendline problem with Office.Interop.Excel and C# .Ne

B

Barry M.

I am not able to add a trendline to an Excel chart using
Microsoft.Office.Interop.Excel library from Visual Studio 2008, using C#.
Works OK with VB .Net, however.

The following code works as expected using VB .Net:
oChart.SeriesCollection(1).Select()
oChart.SeriesCollection(1).Trendlines.Add(Excel.XlTrendlineType.xlPolynomial,
Order:=3, Forward:=0, Backward:=0, DisplayEquation:=True,
DisplayRSquared:=True).Select()

But, this equivalent C# code does not compile:
oChart.SeriesCollection(1).Select();
oChart.SeriesCollection(1).Trendlines.Add(
Excel.XlTrendlineType.xlPolynomial, //type
3, // order
Missing.Value, // period
Missing.Value, // forward
Missing.Value, // backward
Missing.Value, // intercept
true, // display equation
true, // display R squared
Missing.Value).Select();

These C# lines seem to work:

Excel.Series oSeries = (Excel.Series)oChart.SeriesCollection(1);
oSeries.Select();

But, I still can't get the trendline Add to work, for example:

oSeries.Trendlines.Add( ...)

Any ideas why the trendlines automation does not work?

Thank you,
Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top