无效参数 - c# Excel Interop Series.Points()

Invalid parameter - c# Excel Interop Series.Points()

一段时间以来,我一直在努力弄清楚这个问题,但似乎一无所获。我只是想使用 C# 更改 Excel 柱形图中最后一列的颜色(例如,前 3 列为蓝色,最后一列为橙色)。我搜索了许多论坛和 Interop class 定义,但无济于事。

代码如下:

Microsoft.Office.Interop.Excel.Series series1 = (Series)xlChart.SeriesCollection(2);
series1.Interior.Color = newColorList[0];

Microsoft.Office.Interop.Excel.Point point1 = (Point)series1.Points(4); //this line throws an exception
point1.Interior.Color = newColorList[7];

第三行抛出一个 "Invalid Parameter" 异常,尽管我进行了搜索,但我还是不知道如何修复它。感谢任何帮助,特别是如果我应该走不同的路线来更改最后一列的颜色。

提前致谢!

积分指数从1开始。 你确定你的图表中有第 4 个点吗? 我用了

((Excel.Point)((Excel.Series)expchart.Chart.SeriesCollection(iseries)).Points(ipoint)).Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(160, 160, 160).ToArgb();

而且有效。