如何以编程方式设置 SpreadsheetGear 中图表系列的值?

发布于 2024-10-01 02:52:42 字数 538 浏览 2 评论 0原文

根据 MSDN,Excel 允许设置值以编程方式从数组获取图表系列的属性:

Charts("Chart1").SeriesCollection(1).Values = _ Array(1, 3, 5, 7, 11, 13, 17, 19)

如何使用 SpreadsheetGear 图表执行此操作?在我的特定问题中,引用单元格范围是不可行的。我尝试将值设置为双精度列表和格式为“1,3,5,...,19”的字符串。这两种方法都不起作用,并且 SpreadsheetGear 的文档 没有提供预期格式的示例。

According to MSDN, Excel permits setting the Values property of a chart series programmatically from an array:

Charts("Chart1").SeriesCollection(1).Values = _
Array(1, 3, 5, 7, 11, 13, 17, 19)

How do I do this with a SpreadsheetGear chart? In my particular problem, referring to a cell range is not feasible. I have tried to set the Values to a list of doubles and to a string of the format "1, 3, 5, ..., 19". Neither of those ways works, and SpreadsheetGear's documentation gives no examples of the expected format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2024-10-08 02:52:42

您可以使用由图表系列常量值数组组成的公式。您需要将传递到 ISeries.Values 的字符串格式化,如下所示:“={1,2,3,4}”。下面是一个更完整的示例,它替换了图表中的第一个系列,假设您在打开的工作簿中的工作表“Sheet1”上有一个图表名称“Chart 1”:

IWorkbook workbook = Factory.GetWorkbook(@"C:\chart.xlsx");
SpreadsheetGear.Charts.IChart chart = workbook.Worksheets["Sheet1"].Shapes["Chart 1"].Chart;
ISeries series1 = chart.SeriesCollection[0];
series1.Values = "={10,20,30,40,50,60}";
workbook.Save();

一些附加说明。为了获得与 Excel 的最佳兼容性,您需要使用 Open XML (XLSX/XLSM) 文件格式。将上述文件保存为 XLSX/XLSM 后,Excel 可以毫无问题地读取该文件。但是,Excel 会将此系列公式转换为静态“数据缓存”,并删除上面的系列公式。 SpreadsheetGear 对这种“数据缓存”的支持有限(我们读入它,但不将其写出到文件格式),因此取决于设置系列后您将在 SpreadsheetGear 和 Excel 之间进行多少交互和保存根据上述公式,在 SpreadsheetGear 和 Excel 之间多次传递后,在 SpreadsheetGear 中打开此工作簿时,您可能会遇到这些限制。如果您只是将本工作簿用于报告目的,那么您应该不会遇到任何问题。

You can use a formula consisting of an array of constant values for a chart series. You’ll need to format the string passed into ISeries.Values as follows: “={1,2,3,4}”. Here is a more complete example that replaces the first series in a chart, assuming you have a chart name “Chart 1” on worksheet “Sheet1” in the opened workbook:

IWorkbook workbook = Factory.GetWorkbook(@"C:\chart.xlsx");
SpreadsheetGear.Charts.IChart chart = workbook.Worksheets["Sheet1"].Shapes["Chart 1"].Chart;
ISeries series1 = chart.SeriesCollection[0];
series1.Values = "={10,20,30,40,50,60}";
workbook.Save();

A couple additional notes. For the best compatibility with Excel, you will need to use the Open XML (XLSX/XLSM) file format. Excel has no problem reading in the file above after it has been saved in XLSX/XLSM. However, Excel will convert this series formula to a static “data cache” and drop the series formula above. SpreadsheetGear has limited support for this “data cache” (we read it in but don’t write it out to the file format), so depending on how much interacting and saving you’ll be doing between SpreadsheetGear and Excel after you set the series formula above, you may run into these limitations upon opening this workbook in SpreadsheetGear after several passes between SpreadsheetGear and Excel. If you are simply using this workbook for reporting purposes, you should not run into any problems whatsoever.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文