Header menu logo ExcelProvider

Getting Started

To start using ExcelProvider simply reference the ExcelProvider NuGet Package.

For use in a project, use the following command in the Package Manager Console:

PM> Install-Package ExcelProvider

For use in an F# script, use the following directive:

#r "nuget: ExcelProvider"

After referencing the package, open FSharp.Interop.Excel and you will have access to the Type Provider functionality.

You can create a type for an individual workbook. The simplest option is to specify just the name of the workbook. You will then be given typed access to the data held in the first sheet. The first row of the sheet will be treated as field names and the subsequent rows will be treated as values for these fields.

Parameters

When creating the type you can specify the following parameters:

All but the first are optional.

The parameters can be specified by position or by using the name - for example the following are equivalent:

open FSharp.Interop.Excel

type MultipleSheets1 = ExcelFile<"MultipleSheets.xlsx", "B">
type MultipleSheets2 = ExcelFile<"MultipleSheets.xlsx", SheetName="B">

Example

This example shows the use of the type provider in an F# script on a sheet containing three rows of data:

alt text

// reference the type provider
open FSharp.Interop.Excel

// Let the type provider do it's work
type DataTypesTest = ExcelFile<"DataTypes.xlsx">
let file = new DataTypesTest()
let row = file.Data |> Seq.head
let test = row.Float

And the variable test has the following value:

1.0
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
namespace FSharp.Interop
namespace FSharp.Interop.Excel
type MultipleSheets1 = ExcelFile<...>
type ExcelFile = inherit ExcelFileInternal
<summary>Typed representation of data in an Excel file.</summary> <param name='FileName'>Location of the Excel file.</param> <param name='SheetName'>Name of sheet containing data. Defaults to first sheet.</param> <param name='Range'>Specification using `A1:D3` type addresses of one or more ranges. Defaults to use whole sheet.</param> <param name='HasHeaders'>Whether the range contains the names of the columns as its first line.</param> <param name='ForceString'>Specifies forcing data to be processed as strings. Defaults to `false`.</param>
type MultipleSheets2 = ExcelFile<...>
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
Multiple items
type DataTypesTest = ExcelFile<...>

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
Multiple items
type ExcelFile = inherit ExcelFileInternal
<summary>Typed representation of data in an Excel file.</summary> <param name='FileName'>Location of the Excel file.</param> <param name='SheetName'>Name of sheet containing data. Defaults to first sheet.</param> <param name='Range'>Specification using `A1:D3` type addresses of one or more ranges. Defaults to use whole sheet.</param> <param name='HasHeaders'>Whether the range contains the names of the columns as its first line.</param> <param name='ForceString'>Specifies forcing data to be processed as strings. Defaults to `false`.</param>

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
Multiple items
val file: DataTypesTest

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
Multiple items
val row: ExcelFile<...>.Row

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
property ExcelFile<...>.Data: System.Collections.Generic.IEnumerable<ExcelFile<...>.Row> with get
Multiple items
module Seq from Microsoft.FSharp.Collections

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
val head: source: 'T seq -> 'T
Multiple items
val test: float

--------------------
ExcelFile<...>() : ExcelFile<...>
ExcelFile<...>(filename: string) : ExcelFile<...>
ExcelFile<...>(filename: string, sheetname: string) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat) : ExcelFile<...>
ExcelFile<...>(stream: System.IO.Stream, format: ExcelFormat, sheetname: string) : ExcelFile<...>
property ExcelFile<...>.Row.Float: float with get

Type something to start searching.