excel - 将deedle框架复制到excel

标签 excel f# deedle

我的目标是有效地复制 deedle frame在 F# 中脱颖而出。 我从未使用过 F# 中的 excel。我受到了启发 this tutorial .

这是我的代码:

#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 中,但从未成功发布,因为这需要一些时间来完善和记录内容。

我们实际上将源代码放在 GitHub 上(作为我的演示演讲之一),所以你 can get it here .
使用这个,你应该能够写:

xl?A1 <- deedleFrame

还有很多你可以做的 - 看看 Xl 类型的成员。

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

关于excel - 将deedle框架复制到excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21164583/

相关文章:

.net - 有没有办法在 F# 中使用 Matlab 图像处理工具箱?

c# - 如何在 Deedle 框架中将值从 <string> 转换为 <double> 类型?

macos - XAMARIN 6.3 MacOS 单声道更新 : F# interactive (and more) crashing

excel - Angular 5 上的 XLSX 缩小版?

excel - 我如何知道我单击的已分配宏的图像的名称

excel - 删除重复项给出 1004 错误

com - F# 2.0、Silverlight 5 和 Excel 互操作

excel - Play框架-dependency.yml未自动生成

F#实例语法