如何closures在F#中打开Exceldocument?

我正在寻找一个closures已打开的Exceldocument的函数。 这就是我打开它的方式:

let xlApp = new Excel.ApplicationClass() let xlWorkBookInput = xlApp.Workbooks.Open(@"C:\Projects\Tool\Versuch\VersuchZuEditieren.xlsx") let viewStateMachine state event = match state, event with | {State = _}, ConsumablesClicked vm -> view.HandleModelChanged { Title = "My Title"; Comment = sprintf "" } let TrackPosition = vm.TrackPosition let xlWorkSheetInput = xlWorkBookInput.Worksheets.["Consumables"] :?> Excel.Worksheet let array = vm.TubePosition.Split([|','|]) let arrayLength = array.Length let addIndex = sprintf "%s%d" let randomNumber = System.Random() for i in 0 .. arrayLength - 1 do xlWorkSheetInput.Cells.[startindex + i + 2, 1] <- vm.TrackPosition xlWorkSheetInput.Cells.[startindex + i + 2, 2] <- array.[i] let randomBarcodePart2 = randomNumber.Next(000000, 999999) xlWorkSheetInput.Cells.[startindex+ i + 2, 3] <- sprintf "%s%06d" vm.FixBarcodePart randomBarcodePart2 startindex <- startindex + arrayLength { State = "Consumables" } 

在这里,我将closures它,但是如何?

从讨论中的意见来看,Excel文档可以被closures

 xlApp.Workbooks.Close()