Reputation: 49
I am modifying a line chart in excel and I want to remove all the series and add new series to the same chart.
I am using the foll code:
Excel.SeriesCollection serColl = chartpage.SeriesCollection();
Excel.Series ser = serColl.Item(4);
ser.Delete();
ser = serColl.Item(3);
ser.Delete();
ser = serColl.Item(2);
ser.Delete();
ser = serColl.Item(1);
ser.Delete();
But I wanted the code to be generic i.e. find the number of series and delete all in a loop. Thanks in advance.
Upvotes: 3
Views: 1445
Reputation: 744
Like so.
Excel.SeriesCollection serColl = chartpage.SeriesCollection();
while(seriesColl.Count > 0)
{
seriesColl.Item(1).Delete();
}
Upvotes: 2