Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no 'secret sauce' added to the latest F# CTP release (Visual Studio 2010 Beta1) to improve Office interop. Perhaps you have F# confused with <a href="http://msdn.microsoft.com/en-us/library/dd264733(VS.100).aspx" rel="noreferrer">C#'s new support for Dynamic</a>.</p> <p>However, Office interop in F# is the same as C# - you can use the native COM APIs or the newer, managed Visual Studio Tools for Office (VSTO) libraries. Unfortunately F# doesn't have the UI-designers for creating VSTO add-ins like C#, so the simplest way to do Office interop is to use the COM APIs.</p> <p>The following snippet creates an Excel worksheet with information about the pictures in your My Pictures folder:</p> <pre><code>#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] :?&gt; _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) &lt;- text let printCsvToExcel rowIdx (csvText : string) = csvText.Split([| ',' |]) |&gt; Array.iteri (fun partIdx partText -&gt; 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)) |&gt; Seq.map (fun filename -&gt; new FileInfo(filename)) |&gt; Seq.map (fun fileInfo -&gt; sprintf "%s, %s, %d, %s" fileInfo.DirectoryName fileInfo.Name fileInfo.Length (fileInfo.CreationTime.ToShortDateString())) |&gt; Seq.iteri (fun idx str -&gt; printCsvToExcel (idx + 1) str) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload