I have developed a powerpoint plugin to insert a line chart with markers This chart number of hours worked on each day for a given week. Program first adds a chart to a slide using AddChart2. Then adds data in the worksheet attached to the chart :
I have created a Series object. I am using below code to select the range of XValues
Series week1 = chartSeriesCollection.NewSeries();
week1.Name = "WEEK-1";
week1.XValues = chartWorkSheet.Range[chartWorkSheet.Cells[2, 1],chartWorkSheet.Cells[7,1]];
week1.Values = chartWorkSheet.Range[chartWorkSheet.Cells[2, 2],chartWorkSheet.Cells[7,2]];
Plugin gives exception on line 3 (i.e. where I assign week1.XValues)
System.Runtime.InteropServices.COMException: 'Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))'
What is a correct way to select XValues? I am unable to find a C# example that helps to resolve above issue.
Solution:
I was assigning a range of cells, instead of values inside them, to the XValues and that caused Type Mismatch error.
I fixed below lines :
week1.XValues = (chartWorkSheet.Range[chartWorkSheet.Cells[2, 1],chartWorkSheet.Cells[7,1]] as Microsoft.Office.Interop.Excel.Range).Value;
week1.Values = (chartWorkSheet.Range[chartWorkSheet.Cells[2, 2],chartWorkSheet.Cells[7,2]] as Microsoft.Office.Interop.Excel.Range).Value;
User contributions licensed under CC BY-SA 3.0