Closed jonsagara closed 3 years ago
I think that the good practice is to use __SOURCE_DIRECTORY__. This is reliably way to be sure that path is correct.
#r "nuget: ExcelProvider"
open FSharp.Interop.Excel
let [<Literal>] File = __SOURCE_DIRECTORY__ + "/Inventory.xlsx"
type InventoryPrices = ExcelFile<File>
but you also can contribute a fix 😝
here https://github.com/fsprojects/ExcelProvider/blob/master/src/ExcelProvider.DesignTime/ExcelProvider.DesignTime.fs#L149 cfg:TypeProviderConfig
come with cfg.ResolutionFolder
that should be used as root folder if filename
is not absolute
// Resolve the filename relative to the resolution folder.
let resolvedFilename = Path.Combine(cfg.ResolutionFolder, filename)
That worked perfectly. Thank you!
A little followup: looks like this is a known issue:
Description
This is more a question on proper usage; I think
ExcelProvider
is behaving correctly.I'm trying to load a spreadsheet at runtime in a
.fsx
file from FSI within Visual Studio. The.xlsx
file resides in the same directory as the.fsx
file.ExcelProvider
is satisfied by the relative path, but when I execute the script, I get aFileNotFoundException
:Here is the script:
At runtime,
ExcelProvider
is looking for my file in the directoryC:\Users\Jon\AppData\Local\Temp\nuget\1932--71a8b809-102e-4160-8619-47f88b5e57f3\Inventory.xlsx
, which of course is different than my development directory where I'm editing the.fsx
file.How do I get ExcelProvider to load the spreadsheet at runtime without hard coding the path to the spreadsheet?
Repro steps
.fsx
file.xlsx
file to the same directory as the.fsx
fileExcelProvider
as demonstrated above.fsx
file in F# Interactive within Visual Studio (I highlighted all the text and pressetALT+ENTER
on my keyboard)Expected behavior
I think this is working correctly because I don't expect the script to know about files and copy them to the correct location.
Actual behavior
ExcelProvider
can't find the spreadsheet because it is executing from a different temp directory.Known workarounds
If I hard code the path to the
.xlsx
file, everything works. However, I'd like to avoid having a hard coded path, if possible.Related information
Thank you,
Jon