Exception for Column-clustered chart in Excel

SKSR

New member
Joined
Aug 12, 2004
Messages
2
Location
Atlanta, Georgia.
Error generating chart in Excel

Hi, this is my first thread here.

Im trying to generate a Column Clustered chart in Excel. But Im coming across the following error: (However, this works fine for Excel.XlChartType.xl3DColumn, and Excel.XlChartType.xlLine but not Excel.XlChartType.xlColumnClustered ) :confused:

An unhandled exception of type System.Runtime.InteropServices.COMException occurred in ExcelCharting.exe

Additional information: Exception from HRESULT: 0x800A03EC.

My code is as follows:

---------------- CODE BEGIN -----------------------

oChart = (Excel._Chart)nExlWkBook.Charts.Add(Missing.Value, Missing.Value,
Missing.Value, Missing.Value );

oChart.Activate();

oResizeRange = nExlWkSheet.get_Range("B2:M3", Missing.Value);

oChart.ChartWizard(oResizeRange, Excel.XlChartType.xlColumnClustered, Missing.Value,
Excel.XlRowCol.xlRows, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);

oSeries = (Excel.Series)oChart.SeriesCollection(1);
oSeries.XValues = nExlWkSheet.get_Range("B1", "M1");
oSeries.Name = "Go Lives";
oSeries = (Excel.Series)oChart.SeriesCollection(2);
oSeries.Name = "Go Lives(planned)";

oChart.Location( Excel.XlChartLocation.xlLocationAsObject, nExlWkSheet.Name );

------------ CODE END -----------------------

The get_range values are good. But I am not sure as to why it is not able to generate the Chart.
Any Suggestions are really appreciated :)
 
Last edited by a moderator:
Finally figured it out...

Atlast, I figured it out. I generated the chart in xlLine mode and then changed it to xlColumnClustered before moving it to the worksheet.

Cool, it worked out. Here is the code:
-------- Code begin ------------------

Excel.ApplicationClass nExlApp = new Excel.ApplicationClass();
nExlApp.Visible = true;
Excel.Workbook nExlWkBook = nExlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet nExlWkSheet = (Excel.Worksheet)nExlWkBook.Worksheets[1];

Excel.Series oSeries;
Excel.Range oResizeRange;
Excel._Chart oChart;

oChart = (Excel._Chart)nExlWkBook.Charts.Add(Missing.Value, Missing.Value,
Missing.Value, Missing.Value );

oChart.Activate();

oResizeRange = nExlWkSheet.get_Range("B2:M3", Missing.Value);

oChart.ChartWizard(oResizeRange, Excel.XlChartType.xlLine, Missing.Value,
Excel.XlRowCol.xlRows, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);

oSeries = (Excel.Series)oChart.SeriesCollection(1);
oSeries.XValues = nExlWkSheet.get_Range("B1", "M1");
oSeries.Name = "Go Lives";
oSeries = (Excel.Series)oChart.SeriesCollection(2);
oSeries.Name = "Go Lives(planned)";

oChart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionBottom;
oChart.ChartType = Excel.XlChartType.xlColumnClustered;

Excel.Chart chart = (Excel.Chart)nExlWkBook.Charts.get_Item(1);
Excel.Series ser = (Excel.Series)chart.SeriesCollection(1);
((Excel.Trendlines)ser.Trendlines(Missing.Value)).Add(Excel.XlTrendlineType.xlLinear,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value);

oChart.Location( Excel.XlChartLocation.xlLocationAsObject, nExlWkSheet.Name );
nExlWkSheet.Shapes.Item(1).ScaleWidth((float)1.60, Microsoft.Office.Core.MsoTriState.msoFalse, Missing.Value);
nExlWkSheet.Shapes.Item(1).ScaleHeight((float)1.30, Microsoft.Office.Core.MsoTriState.msoFalse, Missing.Value);

nExlWkBook.Close(false, Missing.Value, Missing.Value);
nExlApp.Quit();
nExlApp = null;
nExlWkBook = null;
nExlWkSheet = null;
GC.Collect();


-------- Code End ------------------

Anyway, Have a nice weekend you all ;)

- SK :cool:
 
Back
Top