将deedle框架复制到excel

我的目标是有效地复制一个骗子框架 ,在F#中擅长。 我从来没有从F#的excel工作。 我受到这个教程的启发。

这是我的代码:

#r "Microsoft.Office.Interop.Excel" open Microsoft.Office.Interop.Excel /// Export data frame to excel let exportFrameToExcel (frame: Frame<DateTime, string>) (x,y) = // Run Excel as a visible application let app = new ApplicationClass(Visible = true) // Create new file and get the first worksheet let workbook = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet) // Note that worksheets are indexed from one instead of zero let worksheet = (workbook.Worksheets.[1] :?> Worksheet) let mutable col = y+1 for key in frame.ColumnKeys do worksheet.Cells.[x, col] <- key col <- col + 1 for i = 0 to frame.RowCount-1 do let row = frame.GetRowAt(i) let rowKey = frame.GetRowKeyAt(i) worksheet.Cells.[i+x+1, y] <- rowKey for j = 0 to frame.ColumnCount-1 do let value = row.GetAtAs<float>(j) worksheet.Cells.[i+x+1, j+y+1] <- value 

如果在复制数据时触摸excel窗口,速度很慢,可能会崩溃。 我相信有很大的改进空间,例如我认为ApplicationClass应该只在数据被复制时转为visible

我希望能够以一种高效和习惯的方式来完成这项任务的一些指导/帮助。 谢谢。

在BlueMountain(我们完成了Deedle的大部分工作)中,他们实际上有一个将数据传递给Excel的实用程序。 我们想把它包含在Deedle中,但是从来没有设法发布它,因为擦亮和logging东西需要一些时间。

我们实际上把源代码放在GitHub上(作为我演示演示的一部分),所以你可以在这里find它 。
使用这个,你应该能够只写:

 xl?A1 <- deedleFrame 

你可以做更多的事情 – 看一下Xltypes的成员。

此外,我们最初使用NetOffice这是一个更容易使用包装的Excel COM互操作 – 引用的示例没有使用它,但它可能是一个好主意。