开发者

Import Excel data into F#

I would like to import some basic data (only few integers) from an Excel file into a F# list. Here is the code I compute which open an Excel file, take the value of the Cell "C6" and 'store' it in a variable called l. However it does not compiled as an type e开发者_如何学Pythonrror appeared. Indeed type of first value is obj. How can I convert it into int?

//#r "Microsoft.Office.Interop.Excel"

//#r "office"

open Microsoft.Office.Interop


let xlApp = new Excel.ApplicationClass()

let xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\Fabien C\Desktop\algo données.xlsx")

let xlWorkSheet = xlWorkBook.Worksheets.["Produits"] :?> Excel.Worksheet

let firstValue = xlWorkSheet.Cells.[6,3]

let (l : int) = firstValue


I think just add

:?> int

to the end of the last line to downcast firstValue, but see also the linked duplicate question for more on Excel interop.


What is the real type of firstValue? If it's an int, use a dynamic cast:

firstValue :?> int

Otherwise maybe converting to a string and then an int would work:

firstValue |> string |> int
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜