1

我正在尝试将两个系列添加到 Excel 图表中。我可以使用此代码将一个系列添加到图表中。如何在我的图表中再添加一个系列?

worksheet.Select(Type.Missing);
Excel.Range chartRange;
object misValue = System.Reflection.Missing.Value;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)worksheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
Excel.Chart chartPage = myChart.Chart;

chartRange = worksheet.get_Range("B2", "B10");
chartPage.SetSourceData(chartRange, Excel.XlRowCol.xlColumns);
chartPage.ChartType = Excel.XlChartType.xlLine;
var series = (Excel.Series)chartPage.SeriesCollection(1);
series.Values = chartRange;
chartRange = worksheet.get_Range("A2", "A10");
series.XValues = chartRange;
4

1 回答 1

0

不知道它的 C#,但在 VBA 中我会使用类似的东西:

With ChartPage.SeriesCollection.NewSeries
  .Values = ActiveSheet.Range("C2:C10")
End With
于 2013-04-02T12:33:42.330 回答