Click here to Skip to main content
13,054,329 members (122,197 online)
Rate this:
Please Sign up or sign in to vote.
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.

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 8-Feb-13 23:13pm
Shami C332
CHill60 9-Feb-13 17:37pm
How is sheet0 set up?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

Best Regards
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Here is the solution..

chartPage.Location(XlChartLocation.xlLocationAsNewSheet, "Chart Name");

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100