fsprojects / excelprovider Goto Github PK
View Code? Open in Web Editor NEWThis library is for the .NET platform implementing a Excel type provider.
Home Page: http://fsprojects.github.io/ExcelProvider/
License: The Unlicense
This library is for the .NET platform implementing a Excel type provider.
Home Page: http://fsprojects.github.io/ExcelProvider/
License: The Unlicense
I have an excel file with five rows (including headers).
When reading it with the ExcelProvider, I get one extra empty row. Is this the expected behavior?
Get the excel file
Run the following FSharp script:
#r @"..\packages\ExcelProvider.0.8.1\lib\ExcelProvider.dll"
open FSharp.ExcelProvider
[<Literal>]
let excelFilePath = "TestBook.xlsx"
type ExcelWorkbook = ExcelFile<excelFilePath>
let source = new ExcelWorkbook()
source.Data
|> Seq.iter (fun row -> printfn "%A" row)
I expected the data to only include the rows with actual data on them.
When printing the rows, I see one extra row which is empty.
Intellisense for a fsx file shows error after changing column names in excel template file.
Create an Excel template file with columns A and B called test.xlsx. Reference the type provider dll in an fsx file. Create the types using the text.xlsx. Write some code using columns A and B
Change column B to C in the excel file.
Change the naming of column B to C in the fsx file. Intellisense shows and error for using column C. However, the code can be loaded to the fsi without problems. The only way to be able to correct the intellisense problem is by renaming the test.xlsx to for example test1.xlsx and use that file.
Intellisense adjusts to the new column C.
Intellisense keeps refering to column B.
Renaming the template file and using that as type provider.
I'd like to be able to select a range of cells from a fixed top-left and supply the right-most column, but not the number of rows e.g.
Instead of A2:B99
I would like to be able to simply do A2:B
and get all cells until the end of the table. Is this possible?
Please provide a succinct description of your issue.
type ef = ExcelFile<"c:\a\Main1.xls", HasHeaders=false> // ok
// but not for .xlsm files
A CI build on Mac OSX using Mono 3.4.0 has been set up
The main type provider builds but the build is failing when building the tests, see https://travis-ci.org/fsprojects/ExcelProvider/builds/35113927 for example. This may well be a path problem "" instead of "/" but it isn't clear.
The steps to reproduce are in .travis.yml (basically just run build.sh)
When the path of the Excel file is relative. This will not work when moving the compiled code to a different location. The path will still be the absolute path of the original coding location.
Please provide the steps required to reproduce the problem
Create a type with the type provider on a D disk
Try to run the compiled code on a C disk
If the path for the type is the same relative to the working directory, it should be found.
The error you can observe is:
System.TypeInitializationException: The type initializer for 'MyTypeProvider' threw an exception.
---> System.TypeInitializationException: The type initializer for '<StartupCode$BlahBlah>.$Blah' threw an exception.
---> System.Exception: Could not open file 'D:\Development\MyExcel.xlsx'. DirectoryNotFoundException
The path that will be shown in the error message is the exact absolute path that was used when compiling the code.
Using SOURCE_DIRECTORY to create an absolute path gives the same result.
Effectively, this typeprovider can only moved to a location with the same exact absolute path! Meaning I would have to reconfigure a production machine with a D disk just to run this code??
N/A
Is there a F# 3.1, assembly version 4.3.1.0 somewhere that is usable? I installed v4.3.1.0 for VS2013 and got the DLL installed, referencing that still gives problems.
And or, how do I make it work in any way possible?
I think it would be interesting for the provider to support manipulation of online googlesheet data
https://www.google.com/sheets/about/
what do you think :)
I'd like the ability to determine the range at runtime.
I have several files I need to import that contain "bands" of information on the same worksheet. Thus, the range I need to parse moves depending on how much information is in the band above it.
I have code in place to figure out where those ranges are, but don't have a way to specify them when I open the file via the type provider.
At present, I'm sticking with a terrible OleDB-based solution.
The assembly from the nuget package is named ExcelProvider.Runtime.dll
, which disagrees with the current documentation, and seems accidental/odd. Either the docs need to be updated (see issue #64) or the name is incorrect. I presume the name is incorrect, but I didn't want to touch anything before confirming what the expected behavior was.
Please provide the steps required to reproduce the problem
Install the nuget package via paket
Packages folder contains ExcelProvider/lib/net45/ExcelProvider.Runtime.dll
Based on the current documentation and project name, I would expect the dll to be named ExcelProvider.dll
dll is named ExcelProvider.Runtime.dll
Use #r "somePath/ExcelProvider/lib/net45/ExcelProvider.Runtime.dll"
instead of what the docs suggest.
The Tests are failing because of FSharp.Core referencing and deployment issues.
After reading among other things the issue dotnet/fsharp#2399 and not finding a solution, I tried to go around the problem and upgraded the project to 4.4.1.0, but then...
Correlation is not causation but I have noticed that the only two versions of FSharp.Core that are installed in GAC is v4.0_4.3.1.0 and v4.0_4.4.0.0.
If I manually copy the FSharp.Core 4.4.1.0 the tests run fine of course.
If I reference an xslx file with multiple worksheets, it always shows the first sheet, even if I override it with a specific worksheet name in the type constructor.
In ExcelProvider.fsproj, the tag is \bin\Debug instead of bin\Debug. i.e., there's a leading \ that probably shouldn't be there. When you compile in debug mode, it writes the output to C:\bin\Debug.
Enable more flexibility to declaring headers. Currently header can only be the first row in a selected range.
Frequently headers will span 2 or more cells in a column.
Sometimes headers are followed by a blank, or otherwise useless row. Including this row in selection range breaks column type inference.
allow skipping one or more rows in a range after the header, such that type inference only takes place on remaining cells in column
allow for merging 2 or more contiguous cells in a column to be the column header
Currently header can only be the first row in a selected range.
Occurs if enumerate all rows. As a workaround i have selected the entire column and set format to text
System.InvalidCastException: Unable to cast object of type 'System.Double' to type 'System.String'.
at [email protected](Row x) in my.fsx:line 245
at [email protected](b& )
at Microsoft.FSharp.Collections.IEnumerator.MapEnumerator1.System-Collections-IEnumerator-MoveNext() at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable
1 source)
at <StartupCode$FSI_0073>.$FSI_0073.main@()
Stopped due to error
未能加载文件或程序集“ExcelDataReader, Version=3.4.1.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa”或它的某一个依赖项。系统找不到指定的文件。
If you check out the repo on a windows 10 machine and attempt to build it by running build.cmd the build fails after downloading dotnet sdk 2.1.401 and attempting to unzip it.
Please provide the steps required to reproduce the problem
Step A
Clone the repository to local windows 10 machine with Visual Studio and/or Visual Code installed
Step B
Attempt to build by running build.cmd on the command line
The system should build successfully
The system fails to build. It attempts to download sdk 2.1.401 and then to unzip it. Failure message copied below :
Downloading 'https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.401/dotnet-dev-win-x64.2.1.401.zip' to 'C:\Users\aaa\AppData\Local\Temp\dotnet-dev-win-x64.2.1.401.zip'
Running build failed.
Error:
ICSharpCode.SharpZipLib.Zip.ZipException: Cannot find central directory
at ICSharpCode.SharpZipLib.Zip.ZipFile.ReadEntries()
at ICSharpCode.SharpZipLib.Zip.ZipFile..ctor(String name)
at Fake.ZipHelper.Unzip(String target, String fileName) in D:\code\fake\src\app\FakeLib\ZipHelper.fs:line 89
at Fake.DotNetCli.InstallDotNetSDK(String sdkVersion) in D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 567
at System.Lazy1.CreateValue() at System.Lazy
1.LazyInitValue()
at System.Lazy1.get_Value() at [email protected](BuildParams p) at Fake.DotNetCli.Build(FSharpFunc
2 setBuildParams) in D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 203
at [email protected](Unit _arg6)
at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 626
Target Duration
1.CreateValue() at System.Lazy
1.LazyInitValue()1.get_Value() at [email protected](BuildParams p) at Fake.DotNetCli.Build(FSharpFunc
2 setBuildParams) in D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 203No known workarounds at this time
In an Excel file with Sheet1, Sheet2, Sheet3, assuming each has a different type, and assuming the sheetname is given as an argument to the constructor: if the given sheetname is not found at runtime, it is silently ignored and the internally first sheet is used instead.
Note that the "first sheet" is the first you've created. When you move sheets to the right in Excel, the display order changes, but not the internal index of the sheet. The type provider will select the first sheet by index when the sheetname is not found.
Either an error or an empty set.
The type provider takes the first sheet that's programmatically (i.e., inside the XML) the first sheet by index. If this type doesn't match, an error will occur. If the type does match, this can lead to unpredictable behavior, like the same sheet being read twice.
I've researched this with my colleagues but couldn't find a workaround.
Some semblance of a workaround can be created by using the cell-gettors (the dynamic properties from the type provider) and inspect whether the result gives null
, in which case either the sheet is empty, the column is absent, or the wrong sheet is loaded.
Observed with the most recent version of this repo.
When I debug this and inspect the internal fields, you can see that, upon instantiation of the type provider, the internal sheetname is set to the one provided in the constructor. However, the actual data can be something totally different and from a different sheet, because it can silently take the first-sheet-by-index.
I get the following:
Referenced assembly 'C:...\packages\ExcelProvider.0.1.0\lib\net40\ExcelProvider.dll' has assembly level attribute 'Microsoft.FSharp.Core.ComplierServices.TypeProviderAssemblyAttribute' but no public type provider classes were found
This error is generated by:
'''
'''
could you point me in the right direction fixing this?
Thank you
Btw, what is the difference between the ExcelProvider and FSharpx.TypeProviders.Excel ?
If header cell has multiline content type provider generates multiline property name. Code that accesses these properties does not compile.
I am getting something like:
[for x in book.Data -> x.``this
is
a test``]
The sample code I took from the documentation works fine until I have an empty cell.
let valueA = row.ColumnA
This then throws System.InvalidCastException
An unhandled exception of type 'System.InvalidCastException' occurred in sample.exe
Additional information: Unable to cast object of type 'System.DBNull' to type 'System.String'.
What is the recommended way to deal with this? I could catch the exception but this isn't very nice code?
let mutable valueA = Unchecked.defaultof<string>
try
valueA <- row.ColumnA
with ex ->
valueA <- String.Empty
Thank you.
Please update to use the latest version of ProvidedTypes.fs, as described in fsprojects/FSharp.TypeProviders.SDK#121
Hi,
thank you for the library. It's very useful.
I'm using a lot of Structured References (also called "Table Name") in my Excel Sheets for different reasons.
In VBA, I can access these ranges by its name like any range.
For example, a table défined by the range "A1:B5" named "MyRange" can be accessed both ways : range("A1:B5") or range("MyRange").
It's interesting when you have different tables in the same sheets and when their ranges are not know a priori.
Is it possible to do it the same way through the "range" attribute of your method ?
thanks a lot.
Regards
With the change to version 1.0.x the F# interactive is not able to find the designtime dll. It searches in the lib directory while it should be looking in the typeproviders directory,
Reference the runtime dll and open FSharp.Interop.Excel . The fsi will be complaining about the TypeProviderAssembly attribute refering to a designtime dll.
Automatic resolving of path to designtime dll
Cannot find designtime dll.
Copy content of typeproviders directory to lib directory.
Maybe is possible to amend the
[<TypeProviderAssembly("ExcelProvider.DesignTime.dll")>]
statement in ExcelProvider.Runtime.fs
I have a file with multiple sheets and they share the same structure. I would like to generate type from the first sheet and after that instantiate my type on each of the sheets. It can be done by adding optional sheetName parameter to instance constructor.
type MonthlyData = FSharp.ExcelProvider.ExcelFile< @"c:\tmp\x.xlsx", "JAN">
let data =["JAN"; "FEB"; "MAR"] |> List.map (fun x -> MonthlyData(@"c:\tmp\x.xlsx", x)))
I'm currently in a scenario where I'm trying to read the raw text of a formula and parse out a bit of info from it (which is less than ideal, but it's what I've got to work with. Parsing out image urls from a Google sheet downloaded in XLSX form because CSV never provides them, but some data is only stored on there within image formulas so it displays on sheets).
Currently, ExcelProvider only gives me completely blank fields in those particular cases.
It would be nice if in the type definition we can specify that we want to see the textual form of formulas instead of returning blank. Not asking for evaluation or anything of the sort; just the formula itself.
I can't find a way to load an excel file at runtime. I can only use the one specified as a constant in the type provider initialization
There are no steps to reproduce this problem.
I expect to use the the constant file as a "template" and then be able to specify at runtime which file to parse, which will need to have the same structure of the template. Withtout this possibility the type provider is useless in real applications.
I can only load and parse the file I provide as a constant string in the type provider initialization. In other type providers I have used there is a "Load" method to call with a path parameter to specify a different file.
No workarounds found.
The documentation as published at is out of date as of version 1. It is still referring to the old Fsharp.ExcelProvider namespace
Visit the website at and subpages
The documentation should refer to opening Fsharp.Interop.Excel instead
The required changes seem to have already been made in the docs subfolder of the code. However, the generated documentation has not yet been published to the live site.
I would like to use this package on a .NET Standard library.
dotnet add MyProject.csproj package ExcelProvider
ExcelProvider to be installed on project
PS C:\Users\diego\projects\core> dotnet add .\Core\Core.fsproj package ExcelProvider
Microsoft (R) Build Engine version 15.1.545.13942
Copyright (C) Microsoft Corporation. All rights reserved.
Writing C:\Users\diego\AppData\Local\Temp\tmp81DD.tmp
info : Adding PackageReference for package 'ExcelProvider' into project '.\Core\Core.fsproj'.
log : Restoring packages for C:\Users\diego\projects\core\Core\Core.fsproj...
info : CACHE https://api.nuget.org/v3-flatcontainer/excelprovider/index.json
info : CACHE https://api.nuget.org/v3-flatcontainer/excelprovider/0.8.1/excelprovider.0.8.1.nupkg
error: Package ExcelProvider 0.8.1 is not compatible with netstandard1.6 (.NETStandard,Version=v1.6). Package ExcelProvider 0.8.1 supports: net (.NETFramework,Version=v0.0)
error: One or more packages are incompatible with .NETStandard,Version=v1.6.
error: Package 'ExcelProvider' is incompatible with 'all' frameworks in project '.\Core\Core.fsproj'.
None
.NET Command Line Tools (1.0.0-rc4-004777)
Product Information:
Version: 1.0.0-rc4-004777
Commit SHA-1 hash: 18c01886cd
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.0-rc4-004777
I have just been checking out the Excel Type Provider, and my initial attempt to link to an Excel file generates a null reference error (red squiggly with "Object reference not set to..."). Looking at the type provider code, it appears that files are opened by the openWorkbookView function, which in turn relies on readers provided by the ExcelDataReaders project. These readers apparently do not throw exceptions when there is a problem reading; instead, they set IsValid to false and provide an ExceptionMessage describing the error. I believe openWorkbookView should check if the reader IsValid before proceeding, and (presumably) throw an exception with ExceptionMessage if it is not. Hopefully, this will provide somewhat more helpful information about the nature of the problem in a case like mine.
I have prepared a sample app which I can run successfully, but once I try to build a linux docker container using the provided Dockerfile I get the following error:
/src/Program.fs(3,22): error FS3033: The type provider 'FSharp.Interop.Excel.ExcelProvider.ProviderImplementation+ExcelProvider' reported an error: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) [/src/ConsoleApp.fsproj]
ConsoleApp.zip
Extract the project and try to build a linux docker container using the provided Dockerfile.
Successfully build the project inside the docker container.
Docker build fails with error:
/src/Program.fs(3,22): error FS3033: The type provider 'FSharp.Interop.Excel.ExcelProvider.ProviderImplementation+ExcelProvider' reported an error: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) [/src/ConsoleApp.fsproj]
Program.fs(22,22): Error FS3033: The type provider 'ExcelProvider.ExcelProvider+ExcelProvider' reported an error: Could not create ExcelDataReader. Exception - Could not create ExcelDataReader. Exception - Method 'ICSharpCode.SharpZipLib.Zip.ZipEntry.IsCompressionMethodSupported' not found. (FS3033)
type TemplateExcel = ExcelFile<"TemplateType.xlsx">
None that I could find out
Tried various versions of ExcelProvider ranging from 0.1.2 to 0.8.0
Please provide a description of any known workarounds.
I'd like to be able to load data from a System.IO.Stream
For context, I am trying to load data while running inside an Azure Function with a BlobStorage trigger. At that point, I have access to the data I need in the form of a stream.
The workaround (I think) is to write the data out to temp storage and then read it back in using the facility provided (i.e. by providing the file path). If an overload can take a stream, then the workaround is unnecessary.
It looks like at the current state ExcelProvider<>
supports a very limited set of data types, namely float
, bool
, DateTime
(which sometimes is not recognized correctly) and string
.
This issue brings two things:
double
, decimal
, int
, int64
and options. Excels are often used in fields, where float precision is far to weak.Schema
property where types of columns can be specified manually (I found some cases where Date column is treated as float). It doesn't have to be as advanced as in CsvProvider, but something like date,string, string, int option, decimal
would be a great relief.Frequently the column types inferred by the TP are wrong. Implement a schema definition parameter, similar to how CSV TP does. The ability to override only selected columns in the range would be preferred.
ForceString
It would be wonderful if this provider could achieve full CRUD (Create, Read, Update, Delete) on an Excel table. Currently I am using this for reading and OpenXML SDK for writing.
I can't find any support for optional data within the TP - so I'm forced to fall back to working with strings and then converting to e.g. floats.
Have I missed something?
Is there any way (or plans) to allow setting Globalization settings when reading sheets? If you use ForceString = true
, it appears to return the data in the OS culture, rather than the current culture of the app domain that's been set. This causes problems downstream if you then do any parsing operations.
I have an XLS file. Properties for this are shown as the values of the second row rather than the first row (which contains headers).
If I save the file as a XLSX then the headers are correctly used.
I get this error with script files on .NET Framework (not Core).
I use the FSharp Compiler Service with my own WPF editor. As a standalone Editor App the type provider works fine. All good.
But when I host my F# Editor and FCS inside my CAD app (Rhinoceros3D) I get this error message.
The same error is shown in by the FsChecker as well as by FSharp Interactive.
What is different in the hosted context that would trigger this error ? Can I fix this or does this require changes to the type provider ? other Type providers such as FSharp.Data work fine in the hosted context.
I am using FCS 23.0.3
ExcelProvider.0.8.2\lib\ExcelProvider.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found
Build.cmd fails with error FS2026 on windows if run after checkout
Check out the repository onto a Windows machine with Visual Studio 16.4 installed
Attempt to run build with command "./build.cmd" from command line with Administrator Privileges
Expect the libraries to be built successfully.
The build process fails with the following error messages
FSC : error FS2026: Deterministic builds only support portable PDBs (--debug:portable or --debug:embedded) [C:\repos\quintusm\ExcelProvider\src\ExcelProvider.DesignTime\ExcelProvider.DesignTime.fsproj]
FSC : error FS2026: Deterministic builds only support portable PDBs (--debug:portable or --debug:embedded) [C:\repos\quintusm\ExcelProvider\src\ExcelProvider.DesignTime\ExcelProvider.DesignTime.fsproj]
FSC : error FS2026: Deterministic builds only support portable PDBs (--debug:portable or --debug:embedded) [C:\repos\quintusm\ExcelProvider\src\ExcelProvider.DesignTime\ExcelProvider.DesignTime.fsproj]
Not currently aware of any workarounds
There is no way to refer to an embedded resource as template to construct the type now.
None
This renaming was done in #61
I'm new to F# so this may well be user error...
I get the following error when trying to run a simple solution:
error FS3033: The type provider 'FSharp.Interop.Excel.ExcelProvider.ProviderImplementation+ExcelProvider' reported an error: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file.
I was going to log as an issue but I'm not sure whether the ExcelProvider is actually meant to work on .net core yet?
Use full framework? Code works fine when running from .fsx, and intellisense (Ionide in vscode) is working correctly at design time.
ExcelProvider 1.0.1
.2.2.202
and 3.0.100-preview3-010431
.TargetFramework
of netcoreapp2.1
and netcoreapp3.0
respectively in .fsproj
.System.Text.Encoding.CodePages
in solutions using both the dotnet add package ...
and paket add ...
with local /packages
folder approaches.Run "build.cmd Release"
==> all tests fail with "MethodNotFoundException"
Currently the project uses a version of FSharp.TypeProviders.StarterPack
which seems to not have correct redirecting of FSharp.Core
references to the one used by the compiling project.
If you have latest F# tools installed which uses an FSharp.Core
with assembly version 4.4.3.0
, the TP currently generates a reference to that, even if the project itself references a lower version.
FSharp.Core
assembly references redirected to the one used by the compiling project. This should be handled correctly by current implementation in FSharp.TypeProviders.SDK
.
Failing to find FSharp.Core
version 4.4.3.0
at runtime although the project was not referencing it.
Update project to use latest FSharp.Core. Add downwards assembly redirects to app/web.config
.
ExcelProvider 0.8.2
I don't know how many rows the TP reads before attempting to infer column types, but it is not enough. Type inference is frequently incorrect because the TP did not recognize (for instance) that a blank cell appears in the column, which should render it an option type, or that a decimal number appears further down a column, and so the type should not be int.
Conduct some experiments to come up with a greater number of rows consumed to do type inference, but not so many it impacts performance too much. More rows is better.
ForceString - not a nice alternative
Would be nice if the type provider had HasHeaders = true|false
parameter to support spreadsheets/regions without headers.
The trailing whitespace makes diffs quite hard to read (lots of red blocks). I'd be happy to do it, but I'd end up having "contributed" a lot more than is fair. Also, not everyone cares about code sanity like I do, so I'll defer to your judgement :).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.