使用Excel在F#中绘图

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

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

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

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

我有一个例子,说明如何在真实世界function编程书中做到这一点。 第13章首先下载一些数据,然后将它们添加到Excel并创build一个graphics。

  • 你可以在这里得到完整的源代码 。

下面的代码片段不是一个完整的(工作)代码,因为它依赖于之前构build的一些对象,但它可以给你一个想法如何做到这一点:

// 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