C
ChartsToBe
Continued from my previous question on Charting...
I now have this code, it will get to the second series and then it dies with
this error.
System.InvalidCastException was unhandled
OleAut reported a type mismatch.
....on this line...
mySeries[1] =
mySeriesCollection.Add((Excel.Range)myWorksheet.get_Range("D2", "D13"),
Excel.XlRowCol.xlColumns, false, false, false);
I'm not seeing where the Casting issue is here. After all it, completes the
series line on the chart, then gets the exception.
Here is the method in full:
mySeries = new Microsoft.Office.Interop.Excel.Series[4];
myChart = myWorkbook.Charts.Add(missing, missing, missing,
missing) as Excel.Chart;
myExcelApp.ActiveChart.ChartType =
Excel.XlChartType.xlXYScatterSmooth;
myExcelApp.ActiveChart.Name = "Time Analysis Chart";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(1);
myExcelApp.ActiveChart.SetSourceData(myWorksheet.get_Range("D2",
"D13"),
Excel.XlRowCol.xlColumns);
mySeriesCollection =
(Excel.SeriesCollection)myChart.SeriesCollection(missing);
mySeries[0] = mySeriesCollection.Item(mySeriesCollection.Count);
mySeries[0].Name = "5442";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(2);
mySeries[1] = mySeriesCollection.Add(myWorksheet.get_Range("D2",
"D13"), Excel.XlRowCol.xlColumns, false, false, false);
mySeries[1].Name = "5441";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(3);
mySeries[2] = mySeriesCollection.Add(myWorksheet.get_Range("D2",
"D13"), Excel.XlRowCol.xlColumns, false, false, false);
mySeries[2].Name = "5440";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(4);
mySeries[3] = mySeriesCollection.Add(myWorksheet.get_Range("D2",
"D13"), Excel.XlRowCol.xlColumns, false, false, false);
mySeries[3].Name = "5439";
Thanks, in advance
I now have this code, it will get to the second series and then it dies with
this error.
System.InvalidCastException was unhandled
OleAut reported a type mismatch.
....on this line...
mySeries[1] =
mySeriesCollection.Add((Excel.Range)myWorksheet.get_Range("D2", "D13"),
Excel.XlRowCol.xlColumns, false, false, false);
I'm not seeing where the Casting issue is here. After all it, completes the
series line on the chart, then gets the exception.
Here is the method in full:
mySeries = new Microsoft.Office.Interop.Excel.Series[4];
myChart = myWorkbook.Charts.Add(missing, missing, missing,
missing) as Excel.Chart;
myExcelApp.ActiveChart.ChartType =
Excel.XlChartType.xlXYScatterSmooth;
myExcelApp.ActiveChart.Name = "Time Analysis Chart";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(1);
myExcelApp.ActiveChart.SetSourceData(myWorksheet.get_Range("D2",
"D13"),
Excel.XlRowCol.xlColumns);
mySeriesCollection =
(Excel.SeriesCollection)myChart.SeriesCollection(missing);
mySeries[0] = mySeriesCollection.Item(mySeriesCollection.Count);
mySeries[0].Name = "5442";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(2);
mySeries[1] = mySeriesCollection.Add(myWorksheet.get_Range("D2",
"D13"), Excel.XlRowCol.xlColumns, false, false, false);
mySeries[1].Name = "5441";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(3);
mySeries[2] = mySeriesCollection.Add(myWorksheet.get_Range("D2",
"D13"), Excel.XlRowCol.xlColumns, false, false, false);
mySeries[2].Name = "5440";
myWorksheet = (Excel.Worksheet)myWorkbook.Worksheets.get_Item(4);
mySeries[3] = mySeriesCollection.Add(myWorksheet.get_Range("D2",
"D13"), Excel.XlRowCol.xlColumns, false, false, false);
mySeries[3].Name = "5439";
Thanks, in advance