I am currently trying to chart my S&P, M2, CC data in excel, through C#. However my code keeps crashing at this line below and throwing this kind of error (The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)))
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10,80,300,250);// this are just test numbers
The first thing I did was create a fourth sheet in my excel workbook, however for some reason my code places my sheet right before my active sheet, so it looks "Chart 4" "Something 1" "Something 2" "Something 3". Not sure if this is anything to worry about, but just throwing that out there.
Here is all my code for this function, I wanted to throw this code in a class of its own, a class design to handle the creation of the excel chart but out of desperation decided to move it back to my class where I handle the creation of the excel doc, thinking that would work but it was all for nothing.
public void createChart()
{
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)getWorkSheet(4).ChartObjects(misValue);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10,80,300,250); <-------- Exception thrown here
Excel.Chart chartPage = myChart.Chart;
chartPage.ChartType = Excel.XlChartType.xlLine;
chartRange = worksheet.get_Range("B4","B100");
chartPage.SetSourceData(chartRange,Excel.XlRowCol.xlColumns);
}
Also I have read somewhere that someone created the new sheet, than created the chart on that sheet, but switch back to what I am guessing is the active sheet to define the range for the chart, not sure why that would work. Every example I've looked at has the same line of code as me, so it is most likely dealing with the COM and I am not very familiar with.
I've also read that it might have something to do with the GC, but I don't see how that is possible considering where it broke at.
Thanks for any help, I've been on this problem for almost a week now. If you need more of my code to figure help solve the problem I will be glad to post as much of it as you need.
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10,80,300,250);// this are just test numbers
The first thing I did was create a fourth sheet in my excel workbook, however for some reason my code places my sheet right before my active sheet, so it looks "Chart 4" "Something 1" "Something 2" "Something 3". Not sure if this is anything to worry about, but just throwing that out there.
Here is all my code for this function, I wanted to throw this code in a class of its own, a class design to handle the creation of the excel chart but out of desperation decided to move it back to my class where I handle the creation of the excel doc, thinking that would work but it was all for nothing.
public void createChart()
{
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)getWorkSheet(4).ChartObjects(misValue);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10,80,300,250); <-------- Exception thrown here
Excel.Chart chartPage = myChart.Chart;
chartPage.ChartType = Excel.XlChartType.xlLine;
chartRange = worksheet.get_Range("B4","B100");
chartPage.SetSourceData(chartRange,Excel.XlRowCol.xlColumns);
}
Also I have read somewhere that someone created the new sheet, than created the chart on that sheet, but switch back to what I am guessing is the active sheet to define the range for the chart, not sure why that would work. Every example I've looked at has the same line of code as me, so it is most likely dealing with the COM and I am not very familiar with.
I've also read that it might have something to do with the GC, but I don't see how that is possible considering where it broke at.
Thanks for any help, I've been on this problem for almost a week now. If you need more of my code to figure help solve the problem I will be glad to post as much of it as you need.