There is no “secret sauce” added to the latest version of F # CTP (Visual Studio 2010 Beta1) to improve interaction with Office. Perhaps your F # is confused with the new C # support for dynamic .
Microsoft F # # - COM-API , Visual Studio Tools Office (VSTO). , F # UI- VSTO, #, Office - COM-API.
Excel " ":
#r "Microsoft.Office.Interop.Excel"
open System
open System.IO
open System.Reflection
open Microsoft.Office.Interop.Excel
let app = ApplicationClass(Visible = true)
let sheet = app.Workbooks
.Add()
.Worksheets.[1] :?> _Worksheet
let setCellText (x : int) (y : int) (text : string) =
let range = sprintf "%c%d" (char (x + int 'A')) (y+1)
sheet.Range(range).Value(Missing.Value) <- text
let printCsvToExcel rowIdx (csvText : string) =
csvText.Split([| ',' |])
|> Array.iteri (fun partIdx partText -> setCellText partIdx rowIdx partText)
let rec filesUnderFolder basePath =
seq {
yield! Directory.GetFiles(basePath)
for subFolder in Directory.GetDirectories(basePath) do
yield! filesUnderFolder subFolder
}
printCsvToExcel 0 "Directory, Filename, Size, Creation Time"
filesUnderFolder (Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))
|> Seq.map (fun filename -> new FileInfo(filename))
|> Seq.map (fun fileInfo -> sprintf "%s, %s, %d, %s"
fileInfo.DirectoryName
fileInfo.Name
fileInfo.Length
(fileInfo.CreationTime.ToShortDateString()))
|> Seq.iteri (fun idx str -> printCsvToExcel (idx + 1) str)