2013-09-03 10 views
1

Je recherche une fonction pour fermer un document Excel ouvert. Voilà comment je l'ouvre:Comment fermer un document Excel ouvert en F #?

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" } 

Et là, je vais le fermer, mais comment?

+3

De la documentation, il semble que 'xlApp.Workbooks.Close (true)' va faire ce que vous voulez –

+0

Merci pour cela, je doit écrire xlApp.Workbooks.Close() – ThomasFey

Répondre

1

D'après les commentaires dans la discussion, les documents Excel peuvent être fermés avec

xlApp.Workbooks.Close() 
Questions connexes