excel C#中的设置点颜色给出了无效的参数异常

excel C#中的设置点颜色给出了无效的参数异常,c#,excel-interop,C#,Excel Interop,提供无效的参数异常 详情如下: Excel.SeriesCollection seriesCollection = chartPage.SeriesCollection(); Excel.Series series1 = seriesCollection.NewSeries(); series1.XValues = activeSheet.Range["E1", "E3"]; series1.Values = activeSheet.Range["F1", "F3"]; series1.Poi

提供无效的参数异常

详情如下:

Excel.SeriesCollection seriesCollection = chartPage.SeriesCollection();
Excel.Series series1 = seriesCollection.NewSeries();
series1.XValues = activeSheet.Range["E1", "E3"];
series1.Values = activeSheet.Range["F1", "F3"];

series1.Points(0).Format.Fill.ForeColor.RGB = Color.Green.ToArgb();
你要么使用

System.Runtime.InteropServices.COMException was unhandled by user code
  HResult=-2146827284
  Message=Invalid Parameter
  Source=S
  ErrorCode=-2146827284
  StackTrace:
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at Microsoft.Office.Interop.Excel.Series.Points(Object Index)
       at OMSS.BobStats.DrawFractionChart(Worksheet activeSheet, ChartObjects xlCharts, Range xRange, Range yRange) in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.cs:line 104
       at OMSS.BobStats.DrawCharts(Worksheet activeSheet, Range range, Int32 length) in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.cs:line 66
       at OMSS.BobStats.ThisAddIn_Startup(Object sender, EventArgs e) in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.cs:line 52
       at Microsoft.Office.Tools.AddInImpl.OnStartup()
       at Microsoft.Office.Tools.AddInImpl.AddInExtensionImpl.Microsoft.Office.Tools.EntryPoint.OnStartup()
       at Microsoft.Office.Tools.AddInBase.OnStartup()
       at OMSS.BobStats.FinishInitialization() in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.Designer.cs:line 59
       at Microsoft.Office.Tools.AddInBase.Microsoft.Office.Tools.EntryPoint.FinishInitialization()
       at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.ExecutePhase(ExecutionPhases executionPhases)
       at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()
  InnerException: 

编辑:注意点是1索引而不是0索引。您可以使用

System.Runtime.InteropServices.COMException was unhandled by user code
  HResult=-2146827284
  Message=Invalid Parameter
  Source=S
  ErrorCode=-2146827284
  StackTrace:
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at Microsoft.Office.Interop.Excel.Series.Points(Object Index)
       at OMSS.BobStats.DrawFractionChart(Worksheet activeSheet, ChartObjects xlCharts, Range xRange, Range yRange) in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.cs:line 104
       at OMSS.BobStats.DrawCharts(Worksheet activeSheet, Range range, Int32 length) in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.cs:line 66
       at OMSS.BobStats.ThisAddIn_Startup(Object sender, EventArgs e) in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.cs:line 52
       at Microsoft.Office.Tools.AddInImpl.OnStartup()
       at Microsoft.Office.Tools.AddInImpl.AddInExtensionImpl.Microsoft.Office.Tools.EntryPoint.OnStartup()
       at Microsoft.Office.Tools.AddInBase.OnStartup()
       at OMSS.BobStats.FinishInitialization() in c:\Users\t-jasonj\Documents\Visual Studio 2012\Projects\BobStats\ExcelAddIn1\BobStats.Designer.cs:line 59
       at Microsoft.Office.Tools.AddInBase.Microsoft.Office.Tools.EntryPoint.FinishInitialization()
       at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.ExecutePhase(ExecutionPhases executionPhases)
       at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()
  InnerException: 


编辑:注意点是1索引而不是0索引。

它不像ToArgb()中的A。使用&operator将其删除:

series1.Points(1).Format.Fill.ForeColor.RGB = Excel.XlRgbColor.rgbGreen

它不喜欢ToArgb()中的A。使用&operator将其删除:

series1.Points(1).Format.Fill.ForeColor.RGB = Excel.XlRgbColor.rgbGreen

啊这个奏效了。但正如注释所示,点(0)不起作用。点的索引为1,而不是0。我花了很长时间才弄明白>谢谢你,但我已经重写了你的代码行,没有注意到,再次感谢你,我编辑了你的答案以反映我的变化:P不想混淆其他可能有相同问题的人。啊,这很有效。但正如注释所示,点(0)不起作用。点的索引为1,而不是0。我花了很长时间才弄明白>谢谢你,但我已经重写了你的代码行,没有注意到,再次感谢你,我编辑了你的答案以反映我的变化:P不想混淆其他可能有同样问题的人。