Delete all existing excel chart series

别说谁变了你拦得住时间么 提交于 2019-12-23 16:17:06

问题


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.


回答1:


Like so.

Excel.SeriesCollection serColl = chartpage.SeriesCollection();
while(seriesColl.Count > 0)
{
        seriesColl.Item(0).Delete();
}


来源:https://stackoverflow.com/questions/34013273/delete-all-existing-excel-chart-series

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!