Unable to select Values for X-axis of a Powerpoint line chart

0

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 :

Weekly data for number of hours worked each day

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.

c#
powerpoint
vsto
office-interop
excel-interop
asked on Stack Overflow Oct 20, 2020 by Vaibhav More • edited Oct 28, 2020 by Vaibhav More

1 Answer

0

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;
answered on Stack Overflow Oct 28, 2020 by Vaibhav More

User contributions licensed under CC BY-SA 3.0