excel - 使用 Excel 在 F# 中绘图

标签 excel f# automation

已经能够使用 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/

相关文章:

excel - 运行时错误 '1004'无法设置Range类的NumberFormat属性

vba - Excel VBA-是否可以在发生错误时调用sub?

recursion - 实现手指树时的类型错误

automation - 什么是工作流程系统?

javascript - Protractor - 比较 2 个数组的差异

c# - 通过 epplus 在 excel 中调用公式

scala - 纯函数式编译器如何用类型信息注释 AST?

ruby - 在 Ruby 中是否有等同于 F# |> (方法链接)的东西?

c# - 从单独的进程中自动化 Visual Studio 实例

c# - 是否有可能在 VS 2010 中将 C# 应用程序的发布版本设置为 "debug"