gpt4 book ai didi

excel - 使用 Excel 在 F# 中绘图

转载 作者:行者123 更新时间:2023-12-02 16:23:49 25 4
gpt4 key购买 nike

已经能够使用 F# 中的答案将数据添加到 Excel 电子表格

F# and Excel integration for .NET 4.0 (Visual Studio 2010 Beta 1)

我发现自己无法弄清楚如何使用插入的数据来创建图表(在 Excel 中使用 F# 以编程方式)。如何做到这一点?

我正在使用 Excel 2007(Office 12 组件)和 F# 2.0(如果相关的话)。

最佳答案

我在《真实世界函数式编程》一书中有一个示例,展示了如何做到这一点。 第 13 章首先下载一些数据,然后将它们添加到 Excel 并创建图表。

以下代码片段不是完整的(工作)代码,因为它依赖于之前构建的一些对象,但它可以让您了解如何做到这一点:

// Add new item to the charts collection
let chartobjects = (worksheet.ChartObjects() :?> ChartObjects)
let chartobject = chartobjects.Add(400.0, 20.0, 550.0, 350.0)

// Configure the chart using the wizard
chartobject.Chart.ChartWizard
(Title = "Area covered by forests",
Source = worksheet.Range("B2", "E" + endColumn),
Gallery = XlChartType.xl3DColumn, PlotBy = XlRowCol.xlColumns,
SeriesLabels = 1, CategoryLabels = 1,
CategoryTitle = "", ValueTitle = "Forests (mil km^2)")

// Set graphical style of the chart
chartobject.Chart.ChartStyle <- 5

关于excel - 使用 Excel 在 F# 中绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3145781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com