L
Leeder
We are writing C# code to manipulate PowerPoint presentations. In so doing,
we are having to use the Primary Interop Assemblies (PIA) for Office (in this
case, Interop.Microsoft.Office.Core, Microsoft.Office.Interop.Graph, and
Microsoft.Office.Interop.PowerPoint). A road-block we've encountered is
adding a Trendline to a chart inside a slide via code. We can reference
existing Trendlines but cannot seem to create them. For example (minus all
the namespace prefixes for the types):
Graph.Chart newChart1;
newChart1 = (Graph.Chart)presentation.Slides[1].Shapes.AddOLEObject([long
parameter list]).OLEFormat.Object;
/*** Assume data has now been inserted into the datasheet cells which would
establish the collection of Series ***/
Graph.Series series1 = (Graph.Series)newChart1.SeriesCollection(1);
/*** The line below will throw a compilation error because the only exposed
"Trendlines" property or method through the Graph.Series object is method -
object Trendlines(object index) ***/
Graph.Trendlines trendlinesCollection1 = series1.Trendlines;
/*** The line below will throw an error ("Trendlines method of Series class
failed...") because no Trendlines exist against the series yet to be able to
reference them by the index 1...n ***/
Graph.Trendline trendline1 = series1.Trendlines(1);
/*** end of code ***/
When looking in the Object Browser at the Microsoft.Office.Interop.Graph
reference there is an apparent Add( ) function from the Graph.Trendlines
(collection) object but there doesn't appear to be a way to get a reference
to the Trendlines collection. Has anyone ever solved this, or is the
Trendlines collection just not exposed in the PIA to get it from the Series
object.
P.S. - I am aware that in VBA, the following is possible:
With newChart1.SeriesCollection(1).Trendlines
.Add xlLinear
End With
But, as mentioned above, it will failed to compile in C#.
Any Help?!
we are having to use the Primary Interop Assemblies (PIA) for Office (in this
case, Interop.Microsoft.Office.Core, Microsoft.Office.Interop.Graph, and
Microsoft.Office.Interop.PowerPoint). A road-block we've encountered is
adding a Trendline to a chart inside a slide via code. We can reference
existing Trendlines but cannot seem to create them. For example (minus all
the namespace prefixes for the types):
Graph.Chart newChart1;
newChart1 = (Graph.Chart)presentation.Slides[1].Shapes.AddOLEObject([long
parameter list]).OLEFormat.Object;
/*** Assume data has now been inserted into the datasheet cells which would
establish the collection of Series ***/
Graph.Series series1 = (Graph.Series)newChart1.SeriesCollection(1);
/*** The line below will throw a compilation error because the only exposed
"Trendlines" property or method through the Graph.Series object is method -
object Trendlines(object index) ***/
Graph.Trendlines trendlinesCollection1 = series1.Trendlines;
/*** The line below will throw an error ("Trendlines method of Series class
failed...") because no Trendlines exist against the series yet to be able to
reference them by the index 1...n ***/
Graph.Trendline trendline1 = series1.Trendlines(1);
/*** end of code ***/
When looking in the Object Browser at the Microsoft.Office.Interop.Graph
reference there is an apparent Add( ) function from the Graph.Trendlines
(collection) object but there doesn't appear to be a way to get a reference
to the Trendlines collection. Has anyone ever solved this, or is the
Trendlines collection just not exposed in the PIA to get it from the Series
object.
P.S. - I am aware that in VBA, the following is possible:
With newChart1.SeriesCollection(1).Trendlines
.Add xlLinear
End With
But, as mentioned above, it will failed to compile in C#.
Any Help?!