使用Excel在F#中绘图

Muh*_*uri 3 excel f# automation

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

.NET 4.0的F#和Excel集成(Visual Studio 2010 Beta 1)

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

我正在使用Excel 2007(Office 12组件)和F#2.0,如果这是相关的.

Tom*_*cek 5

我有一个例子,展示了如何在真实世界的功能编程书中做到这一点.在第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
Run Code Online (Sandbox Code Playgroud)