Has anyone got experience of writing values to an Excel spreadsheet from F# using Microsoft.Office.Interop? I can read values fine, but when I try to change the value of a cell I always get an error. I have seen posts with this error where column or row are 0, but in my case those values are always positive. I am getting my Excel Application object from excel-dna.
let getCell (sheet: Excel.Worksheet) (row: int, col:int) =
let rng = sheet.Cells.Item(row, col) :?> Excel.Range
match isNull rng with
| true ->
None
| false ->
match isNull rng.Value2 with
| true -> None
| false ->
let s = "Hello"
let o = s :> obj // passing in unboxed string does not help
rng.Value2 <- o // this line throws an error Exception from HRESULT: 0x800A03EC Error
Some rng.Value2