Created
February 9, 2016 02:47
-
-
Save jeremyhoughton/ad7a547d6825990dcdb0 to your computer and use it in GitHub Desktop.
Example of Reading an Excel Workbook using ExcelDataReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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