Excel C# Com 图表多系列问题
请有人帮我解决这个问题,因为这让我发疯!
我正在实用地使用 C# 和 COM 接口创建 Excel 图表。
我已经使用图表向导创建了图表。
然后我想向该图表添加更多系列。我可以添加该系列,但额外的数据位于新列上,并且不会自动创建。
我是否以错误的方式处理这个问题?
添加图表:
public void MakeExcelChart(string startRange, string endRange, string chartTitle, string seriesName)
{
ExcelChart = (Excel.Chart)ExcelWBook.Charts.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ExcelApp.Visible = true;
ExcelChart.HasTitle = true;
ExcelChart.ChartTitle.Text = chartTitle;
ExcelRange = ExcelWSheet.get_Range(startRange, endRange);
ExcelChart.ChartWizard(ExcelRange, Excel.XlChartType.xlColumnClustered, Missing.Value, Excel.XlRowCol.xlColumns, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ExcelChart.ApplyDataLabels(Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowBubbleSizes, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ExcelChart.ChartArea.Fill.OneColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1, 1);
GetSeriesCollection();
ExcelSeries = ExcelSeriesCollection.Item(1);
ExcelSeries.Name = seriesName;
}
并添加系列:
public void AddSeries(string col1, string col2, string startRange, string endRange, string seriesName)
{
ExcelSeries = ExcelSeriesCollection.NewSeries();
ExcelSeries.HasDataLabels = true;
ExcelRange = ExcelWSheet.get_Range(col1+startRange, col1+endRange);
ExcelSeries.XValues = ExcelRange;
ExcelRange = ExcelWSheet.get_Range(col2+startRange, col2+endRange);
ExcelSeries.Values = ExcelRange;
ExcelChart.HasLegend = true;
ExcelSeries.Name = seriesName;
}
Please can someone help me with this as it's driving me nuts!
I'm creating an excel chart using C# and the COM interface pragmatically.
I've created the chart using the chart wizard.
I want to then add more series to this chart. I can add the series but the extra data is on new columns and they are not automatically created.
Am I going about this the wrong way?
Add Chart:
public void MakeExcelChart(string startRange, string endRange, string chartTitle, string seriesName)
{
ExcelChart = (Excel.Chart)ExcelWBook.Charts.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ExcelApp.Visible = true;
ExcelChart.HasTitle = true;
ExcelChart.ChartTitle.Text = chartTitle;
ExcelRange = ExcelWSheet.get_Range(startRange, endRange);
ExcelChart.ChartWizard(ExcelRange, Excel.XlChartType.xlColumnClustered, Missing.Value, Excel.XlRowCol.xlColumns, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ExcelChart.ApplyDataLabels(Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowBubbleSizes, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ExcelChart.ChartArea.Fill.OneColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1, 1);
GetSeriesCollection();
ExcelSeries = ExcelSeriesCollection.Item(1);
ExcelSeries.Name = seriesName;
}
And to add series:
public void AddSeries(string col1, string col2, string startRange, string endRange, string seriesName)
{
ExcelSeries = ExcelSeriesCollection.NewSeries();
ExcelSeries.HasDataLabels = true;
ExcelRange = ExcelWSheet.get_Range(col1+startRange, col1+endRange);
ExcelSeries.XValues = ExcelRange;
ExcelRange = ExcelWSheet.get_Range(col2+startRange, col2+endRange);
ExcelSeries.Values = ExcelRange;
ExcelChart.HasLegend = true;
ExcelSeries.Name = seriesName;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情。它对我来说非常有效。
然后,您可以单独更改每个系列的参数,例如:
等等。
try something like this. It works for me pretty well.
you can then change parameters of each series individually for example:
and so on.
您需要扩展定义数据的 Excel 表。
很好的例子是在
http://blogs.msdn.com/vsod/archive/2009/06/15/creating-charts-in-word-and-powerpoint-使用新引入的对象模型-in-office-2007-service-pack-2.aspx
You need to extend the Excel table that is defining the data.
Good example is at
http://blogs.msdn.com/vsod/archive/2009/06/15/creating-charts-in-word-and-powerpoint-using-newly-introduced-object-model-in-office-2007-service-pack-2.aspx