Skip to content

Instantly share code, notes, and snippets.

@jeremyhoughton
Created February 9, 2016 02:47
Show Gist options
  • Save jeremyhoughton/ad7a547d6825990dcdb0 to your computer and use it in GitHub Desktop.
Save jeremyhoughton/ad7a547d6825990dcdb0 to your computer and use it in GitHub Desktop.
Example of Reading an Excel Workbook using ExcelDataReader
#r "../packages/ExcelDataReader/lib/net45/Excel.dll"
#r "../packages/SharpZipLib/lib/20/ICSharpCode.SharpZipLib.dll"
open Excel
open System.IO
open System.Data
open System.Xml
let extractData fileName sheetName =
use stream = File.Open(fileName, FileMode.Open, FileAccess.Read)
use excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
use sheet =
excelReader.AsDataSet().Tables
|> Seq.cast<DataTable>
|> Seq.find (fun sheet -> sheet.TableName = sheetName)
sheet.Rows
|> Seq.cast<DataRow>
|> Seq.map (fun row -> row.ItemArray) |> Seq.toArray
extractData @"C:\SampleInput.xlsx" "Sheet1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment