F # and Excel Integration for .NET 4.0 (Visual Studio 2010 Beta 1)

Can someone give a link to a website or demonstrate here how to integrate F # and Excel using .NET 4.0 (Visual Studio 2010 Beta 1)?

I know how to do this in the CTP release, but as far as I know, in .NET 4.0 (Visual Studio 2010 Beta 1) it should be easier.

+3
source share
2 answers

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 
    }


// Print header
printCsvToExcel 0 "Directory, Filename, Size, Creation Time"


// Print rows
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)
+12

VSTO, F # . VS2010, F # DLL, ....

+1

Source: https://habr.com/ru/post/1714086/


All Articles