I can't believe how complicated this is...

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:)
 
S

Sergei D

I am sorry I did not formulate my question right. In my example I have only
one range (“a8:a30â€). I need it, after it matches the cell = 1122 in column
A, to go to column B and meet another condition. Basically, I need it to
match column A with column B and then I want it to evaluate IF.
 
C

ChartsToBe

I think you submitted that reply to the wrong thread:|

Sergei D said:
I am sorry I did not formulate my question right. In my example I have only
one range (“a8:a30â€). I need it, after it matches the cell = 1122 in column
A, to go to column B and meet another condition. Basically, I need it to
match column A with column B and then I want it to evaluate IF.
--
Sergei D


ChartsToBe said:
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:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top