Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I am writing a C# Interop code to create report in excel with chart in 2nd sheet. I am able create chart, but it is coming in first sheet. Please help get the same in second sheet. My code is here.

C#
Range chartRange;
                Object misValue = System.Reflection.Missing.Value;
                ChartObjects xlCharts = (ChartObjects)sheet0.ChartObjects(Type.Missing);
                ChartObject myChart = (ChartObject)xlCharts.Add(10, 70, 250, 250);
                Chart chartPage = myChart.Chart;
                chartRange = sheet0.get_Range("AN1", "AP6");
                chartPage.SetSourceData(chartRange, misValue);
                chartPage.ChartType = XlChartType.xlColumnClustered;
Posted
Comments
CHill60 9-Feb-13 17:37pm    
How is sheet0 set up?

Hi,

You can create a object for sheet2 as below,
C#
Worksheet sheet2 = workbook.Worksheets[1];


Best Regards
Muthuraja
 
Share this answer
 
Here is the solution..

C#
chartPage.Location(XlChartLocation.xlLocationAsNewSheet, "Chart Name");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900