dfinke / ImportExcel

PowerShell module to import/export Excel spreadsheets, without Excel
https://www.powershellgallery.com/packages/ImportExcel/
Apache License 2.0
2.47k stars 400 forks source link

Import-Excel File Not Found string error #1618

Open mealyman opened 3 months ago

mealyman commented 3 months ago

Not sure if this is an issue or a limitation, but getting these results.
Have tried encapsulating the full path in the command, still throws an error.
If I shorten the name, it seems to work fine.

'C:\Users\username\Downloads\Weekly_system_report [en] (All Locations)-2024-07-25 13-37-03.xlsx' file not found At C:\Users\username\Documents\WindowsPowerShell\Modules\ImportExcel\7.8.9\Public\Import-Excel.ps1:119 char:21

scriptingstudio commented 3 months ago

The problem is with illegal chars in filepath because the module uses default -path parameter which Resolve-Path treates brackets []() as a regular expression. There should be introduced a new parameter -literalpath or, better, illegal chars should be detected and Resolve-Path should switch to -literalpath.

scriptingstudio commented 2 months ago

The work around would be to rename the file removing brackets []() before using Import-Excel

$newname = Rename-Item -LiteralPath <filepath> -NewName (split-path (<filepath> -replace '[\[\]\(\)]') -leaf) -PassThru
Import-Excel $newname.fullname
mealyman commented 2 months ago

The work around would be to rename the file removing brackets []() before using Import-Excel

$newname = Rename-Item -LiteralPath <filepath> -NewName (split-path (<filepath> -replace '[\[\]\(\)]') -leaf) -PassThru
Import-Excel $newname.fullname

Noted, however, doesn't even seem to work now if I have only underscores in the filename.

'C:\Users\username\Downloads\2024_7_2023_Compliance_Report.xlsm' file not found At C:\Users\username\OneDrive - XXX\Documents\WindowsPowerShell\Modules\ImportExcel\7.8.9\Public\Import-Excel.ps1:119 char:21

dfinke commented 2 months ago

Import-Excel .\RVTools_export_all_2024-06-28_03.17.39.xlsx is working for me.

I didn't try it with an xlsm file.

image

mealyman commented 2 months ago

I've modified my code based on what @scriptingstudio provided, and it's working. Thanks for the insights!

scriptingstudio commented 2 months ago

Noted, however, doesn't even seem to work now if I have only underscores in the filename.

It did not work because Rename-Item returned null because the path did not have brackets and could not rename the name to itself.

mealyman commented 2 months ago

Noted, however, doesn't even seem to work now if I have only underscores in the filename.

It did not work because Rename-Item returned null because the path did not have brackets and could not rename the name to itself.

This wasn't using Rename-Item, it was Import-Excel with a straight *.xlsm filename.