diff --git a/FSharpx.TypeProviders.Tests.sln.DotSettings b/FSharpx.TypeProviders.Tests.sln.DotSettings
new file mode 100644
index 00000000..11f2c267
--- /dev/null
+++ b/FSharpx.TypeProviders.Tests.sln.DotSettings
@@ -0,0 +1,3 @@
+
+ <data><IncludeFilters /><ExcludeFilters /></data>
+ <data />
\ No newline at end of file
diff --git a/FSharpx.WithTypeProviders.sln.DotSettings b/FSharpx.WithTypeProviders.sln.DotSettings
new file mode 100644
index 00000000..11f2c267
--- /dev/null
+++ b/FSharpx.WithTypeProviders.sln.DotSettings
@@ -0,0 +1,3 @@
+
+ <data><IncludeFilters /><ExcludeFilters /></data>
+ <data />
\ No newline at end of file
diff --git a/packages/ExcelDataReader.2.1.1/ExcelDataReader.2.1.1.nuspec b/packages/ExcelDataReader.2.1.1/ExcelDataReader.2.1.1.nuspec
new file mode 100644
index 00000000..2c6f96b5
--- /dev/null
+++ b/packages/ExcelDataReader.2.1.1/ExcelDataReader.2.1.1.nuspec
@@ -0,0 +1,22 @@
+
+
+
+ ExcelDataReader
+ 2.1.1
+ ExcelDataReader
+ iciobanu
+ iciobanu
+ http://exceldatareader.codeplex.com/
+ https://nugetgallery.blob.core.windows.net/icons/ExcelDataReader.2.1.png
+ false
+ Lightweight and fast library written in C# for reading Microsoft Excel files ('97-2007).
+ Lightweight and fast library written in C# for reading Microsoft Excel files ('97-2007).
+
+
+
+ Excel
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/ExcelDataReader.2.1.1/content/app.config.transform b/packages/ExcelDataReader.2.1.1/content/app.config.transform
new file mode 100644
index 00000000..8b1f406b
--- /dev/null
+++ b/packages/ExcelDataReader.2.1.1/content/app.config.transform
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/ExcelDataReader.2.1.1/content/web.config.transform b/packages/ExcelDataReader.2.1.1/content/web.config.transform
new file mode 100644
index 00000000..8b1f406b
--- /dev/null
+++ b/packages/ExcelDataReader.2.1.1/content/web.config.transform
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/ExcelDataReader.2.1.1/lib/net20/Excel.dll b/packages/ExcelDataReader.2.1.1/lib/net20/Excel.dll
new file mode 100644
index 00000000..f5b80de4
Binary files /dev/null and b/packages/ExcelDataReader.2.1.1/lib/net20/Excel.dll differ
diff --git a/packages/ExcelDataReader.2.1.1/lib/net20/ICSharpCode.SharpZipLib.dll b/packages/ExcelDataReader.2.1.1/lib/net20/ICSharpCode.SharpZipLib.dll
new file mode 100644
index 00000000..e829ebf4
Binary files /dev/null and b/packages/ExcelDataReader.2.1.1/lib/net20/ICSharpCode.SharpZipLib.dll differ
diff --git a/packages/SharpZipLib.0.86.0/SharpZipLib.0.86.0.nuspec b/packages/SharpZipLib.0.86.0/SharpZipLib.0.86.0.nuspec
new file mode 100644
index 00000000..4783f1f9
--- /dev/null
+++ b/packages/SharpZipLib.0.86.0/SharpZipLib.0.86.0.nuspec
@@ -0,0 +1,14 @@
+
+
+
+ SharpZipLib
+ 0.86.0
+ SharpZipLib
+ http://www.icsharpcode.net/
+ http://www.icsharpcode.net/
+ http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
+ false
+ #ziplib (SharpZipLib, formerly NZipLib) is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language).
+ #ziplib (SharpZipLib, formerly NZipLib) is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language).
+
+
\ No newline at end of file
diff --git a/packages/SharpZipLib.0.86.0/lib/11/ICSharpCode.SharpZipLib.dll b/packages/SharpZipLib.0.86.0/lib/11/ICSharpCode.SharpZipLib.dll
new file mode 100644
index 00000000..60ef0c99
Binary files /dev/null and b/packages/SharpZipLib.0.86.0/lib/11/ICSharpCode.SharpZipLib.dll differ
diff --git a/packages/SharpZipLib.0.86.0/lib/20/ICSharpCode.SharpZipLib.dll b/packages/SharpZipLib.0.86.0/lib/20/ICSharpCode.SharpZipLib.dll
new file mode 100644
index 00000000..fe643ebc
Binary files /dev/null and b/packages/SharpZipLib.0.86.0/lib/20/ICSharpCode.SharpZipLib.dll differ
diff --git a/packages/SharpZipLib.0.86.0/lib/SL3/SharpZipLib.Silverlight3.dll b/packages/SharpZipLib.0.86.0/lib/SL3/SharpZipLib.Silverlight3.dll
new file mode 100644
index 00000000..e3fd9620
Binary files /dev/null and b/packages/SharpZipLib.0.86.0/lib/SL3/SharpZipLib.Silverlight3.dll differ
diff --git a/packages/SharpZipLib.0.86.0/lib/SL4/SharpZipLib.Silverlight4.dll b/packages/SharpZipLib.0.86.0/lib/SL4/SharpZipLib.Silverlight4.dll
new file mode 100644
index 00000000..f915af4c
Binary files /dev/null and b/packages/SharpZipLib.0.86.0/lib/SL4/SharpZipLib.Silverlight4.dll differ
diff --git a/packages/repositories.config b/packages/repositories.config
index a8e822fe..4365603e 100644
--- a/packages/repositories.config
+++ b/packages/repositories.config
@@ -1,5 +1,6 @@
+
diff --git a/src/FSharpx.TypeProviders.Excel/ExcelProvider.fs b/src/FSharpx.TypeProviders.Excel/ExcelProvider.fs
index 8b9499ce..a77affd0 100644
--- a/src/FSharpx.TypeProviders.Excel/ExcelProvider.fs
+++ b/src/FSharpx.TypeProviders.Excel/ExcelProvider.fs
@@ -4,50 +4,90 @@ open System.IO
open System
open Samples.FSharp.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
-open Microsoft.Office.Interop
open FSharpx.TypeProviders.Helper
open System.Collections.Generic
-
-let ApplyMoveToRange (rg:Excel.Range) (move:Excel.XlDirection) = rg.Worksheet.Range(rg, rg.End(move))
-
-let internal getRange (xlWorkBookInput : Excel.Workbook) sheetorrangename (headerRow : int) =
- let mysheets = seq { for sheet in xlWorkBookInput.Worksheets do yield sheet :?> Excel.Worksheet }
- let names = seq { for name in xlWorkBookInput.Names do yield name :?> Excel.Name}
- let hasWs = Seq.exists (fun (ws:Excel.Worksheet) -> (ws.Name = sheetorrangename)) mysheets
- if hasWs then
- let sheet = Seq.find (fun (ws:Excel.Worksheet) -> (ws.Name = sheetorrangename)) mysheets
- let firstcell = sheet.Cells.Item(box headerRow, 1) :?> Excel.Range
- ApplyMoveToRange (ApplyMoveToRange firstcell Excel.XlDirection.xlToRight) Excel.XlDirection.xlDown
+open System.Data
+open System
+open Excel
+
+let parseExcelAddress cellAddress =
+
+ let convertToBase radix digits =
+ let digitValue i digit = float digit * Math.Pow(float radix, float i)
+
+ digits
+ |> List.rev
+ |> List.mapi digitValue
+ |> Seq.sum
+ |> int
+
+ let charToDigit char = ((int)(Char.ToUpper(char))) - 64
+
+ let column =
+ cellAddress
+ |> Seq.filter Char.IsLetter
+ |> Seq.map charToDigit
+ |> Seq.toList
+ |> convertToBase 26
+
+ let row =
+ cellAddress
+ |> Seq.filter Char.IsNumber
+ |> Seq.map (string >> Int32.Parse)
+ |> Seq.toList
+ |> convertToBase 10
+
+ (row - 1), (column - 1)
+
+let internal getCells (workbook : DataSet) sheetOrRangeName headerRowIndex =
+ let worksheets = workbook.Tables
+
+ //if sheetOrRangeName refers to a worksheet get the header row from the specified worksheet
+ if worksheets.Contains(sheetOrRangeName) then
+ let sheet = worksheets.[sheetOrRangeName]
+
+ //remove unecessary leading rows
+ if headerRowIndex > 0 then do
+ for row in 0 .. headerRowIndex do
+ let removeRow = sheet.Rows.[headerRowIndex]
+ sheet.Rows.Remove(removeRow);
+ sheet
else
- let hasName = Seq.exists (fun (ws:Excel.Name) -> (ws.Name = sheetorrangename)) names
- if hasName then
- (Seq.find (fun (ws:Excel.Name) -> (ws.Name = sheetorrangename)) names ).RefersToRange
+ let sheet = worksheets.[0]
+ let topLeft = 0, 0
+ let bottomRight =
+ if sheetOrRangeName.Contains(":") then
+ let addresses = sheetOrRangeName.Split(':');
+ let topLeft = parseExcelAddress addresses.[0]
+ let bottomRight = parseExcelAddress addresses.[1]
+
+
else
- failwith (sprintf "Sheet or range %A was not found" sheetorrangename)
+
+
+ else
+ failwith (sprintf "Sheet or range %A was not found" sheetOrRangeName)
// Simple type wrapping Excel data
type ExcelFileInternal(filename, sheetorrangename, headerRow : int) =
- let data =
- let xlApp = new Excel.ApplicationClass()
- xlApp.Visible <- false
- xlApp.ScreenUpdating <- false
- xlApp.DisplayAlerts <- false;
- let xlWorkBookInput = xlApp.Workbooks.Open(filename)
- let xlRangeInput = getRange xlWorkBookInput sheetorrangename headerRow
+ let data =
+ use stream = File.OpenRead(filename)
+ let excelReader =
+ if filename.EndsWith(".xlsx") then ExcelReaderFactory.CreateOpenXmlReader(stream)
+ else ExcelReaderFactory.CreateBinaryReader(stream)
- let objRangeInput = xlRangeInput.Value2 :?> obj[,]
- let res = seq { for irow in 2 .. objRangeInput.GetLength(0) do
- yield seq { for jcol in 1 .. objRangeInput.GetLength(1) do
- yield objRangeInput.[irow,jcol] }
- |> Seq.toArray }
- |> Seq.toArray
+ let workbook = excelReader.AsDataSet()
+ let data = getCells workbook sheetorrangename headerRow
- xlWorkBookInput.Close()
- xlApp.Quit()
- res
+ let res = seq { for irow in 2 .. data.Rows.Count do
+ yield seq { for jcol in 1 .. data.Columns.Count do
+ yield data.Rows.[irow].[jcol] }
+ |> Seq.toArray }
+ |> Seq.toArray
+ res
- member __.Data = data
+ member __.Data = data
type internal ReflectiveBuilder =
static member Cast<'a> (args:obj) =
@@ -102,9 +142,7 @@ let internal typExcel(cfg:TypeProviderConfig) =
let resolvedFilename = Path.Combine(cfg.ResolutionFolder, filename)
let ProvidedTypeDefinitionExcelCall (filename, sheetorrangename, forcestring, headerRow) =
- let xlApp = new Excel.ApplicationClass()
- let xlWorkBookInput = xlApp.Workbooks.Open(resolvedFilename)
-
+
let xlRangeInput = getRange xlWorkBookInput sheetorrangename headerRow
let lines = (seq { for row in xlRangeInput.Rows do yield row } |> Seq.cache)
@@ -142,9 +180,6 @@ let internal typExcel(cfg:TypeProviderConfig) =
prop.AddDefinitionLocation(1, i, filename)
rowTy.AddMember(prop)
- xlWorkBookInput.Close()
- xlApp.Quit()
-
// define the provided type, erasing to excelFile
let ty = ProvidedTypeDefinition(System.Reflection.Assembly.GetExecutingAssembly(), rootNamespace, tyName, Some(typeof))
diff --git a/src/FSharpx.TypeProviders.Excel/app.config b/src/FSharpx.TypeProviders.Excel/app.config
new file mode 100644
index 00000000..b260eab1
--- /dev/null
+++ b/src/FSharpx.TypeProviders.Excel/app.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/FSharpx.TypeProviders.Excel/packages.config b/src/FSharpx.TypeProviders.Excel/packages.config
new file mode 100644
index 00000000..436aa33b
--- /dev/null
+++ b/src/FSharpx.TypeProviders.Excel/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file