简体   繁体   中英

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

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 (ie 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM