简体   繁体   中英

C# VSTO add-in for Excel - Select Chart object by name?

I am developing Excel VSTO add-in. I can programmatically generate several Charts. Now I want to change type of a series of a certain Chart. How can I get the Chart object by it's name?

The code below does not work.

 Microsoft.Office.Interop.Excel.ChartObjects ChObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
 
 Microsoft.Office.Interop.Excel.ChartObject obj = ChObjs.Item("Test Chart");

Thank you very much.

You could try to use the following code snippet below to get Excel sheet Chart object:

Excel.Worksheet excSheet = (Excel.Worksheet)excWorkBook.Worksheets.get_Item(1);//Sheet1
Excel.ChartObjects chartObjects = (Excel.ChartObjects)excSheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)chartObjects.Item(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM