Home » excel » visual studio – How to select existing Chart in Excel using C#

visual studio – How to select existing Chart in Excel using C#

Posted by: admin April 23, 2020 Leave a comment

Questions:

I want to select existing Chart in Excel using C#.
I have a chart Object in my excel file which I want to read it and also Edit it.
I only know to add new chart which is by doing something like this

ChartObjects ChartObjs = null;
ChartObject ChartObj = null;


 ChartObj = ChartObjs.Add(0, 10, 250, 170);

I am using VS 2005 and C#

How to&Answers:

To select an active chart in excel one can use this code

Excel.ChartObject chartObject11 = (Excel.ChartObject)Ws.ChartObjects(1);
chartObject11.Activate();

based on this one can edit the chart and format it.Like changing its datarange or formatting its color or height or width etc etc.

Hope this helps

Answer:

So you’ve defined an object named ChartObj. The chart within the chart object container is ChartObj.Chart, and elements of the chart are ChartObj.Chart.Element.

You ought to have Excel’s VB Editor open so you can check syntax in the VB Object Browser.