I have a user-editable Excel file in a document repository that defines some inputs for an F# program. I'd like to read it using something F#-y, so I thought I would try out FSharpX and their ExcelFile type provider.
The provider is installed via NuGet and enabled, and this works:
open FSharpX
type Example = ExcelFile<"example.xlsx", "Worksheet1", true>
let file = new Example()
for row in File.Data do ......
However, when I try to initialize the constructor with a different file (one I pull out of a database at runtime and stash in a temporary location), I get a really strange type error.
let file = new Example(@"c:\temp\path\to.xlsx")
results in
The type provider 'FSharpx.TypeProviders.ExcelProvider+ExcelProvider' reported an error in the context of provided type 'FSharpx.ExcelFile,filename="example.xlsx",sheetname="Worksheet1",forcestring="True"', member '.ctor'. The error: Type mismatch when splicing expression into quotation literal. The type of the expression tree being inserted doesn't match the type expected by the splicing operation. Expected 'System.String', but received type 'System.Tuple`2[System.String,System.String]'. Consider type-annotating with the expected expression type, e.g., (%% x : string) or (%x : string). Parameter name: receivedType
I have no idea where the tuple it's talking about could be coming from, and I don't have any other ideas about how to initialize this.
Bonus question: What if I wanted to vary over the worksheet name at runtime? The existing FSharpx provider does not seem to allow that.
That's a bug in the provider, not your code. The provided constructor is using the filename you passed in, but the underlying code expects a filename and a workbook name (that's where the tuple ought to come from).