내 목표는 deedle frame을 효율적으로 복사하여 F #에서 능가하는 것입니다. F #에서 Excel로 일한 적이 없습니다. 나는 this tutorial에 의해 고무되었다.deedle frame to 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
그것은 느리고 데이터가 복사되는 동안 내가 엑셀 창을 터치하면 충돌이 발생할 수 있습니다 :
이 내 코드입니다. 개선의 여지가 충분하다고 확신합니다. 예를 들어 ApplicationClass
을 데이터가 복사 된 경우에만 visible
으로 바꾸어야한다고 생각합니다.
효율적이고 관용적 인 방법으로이 작업을 수행하는 데 도움이되는 지침/도움을 보내 주시면 감사하겠습니다. 감사.