dfinke/ImportExcel

Import-Excel File Not Found string error

mealyman opened this issue ยท 7 comments

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

  •                 throw "'$($Path)' file not found"
    
  •                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: ('C:\Users\usern... file not found:String) [], RuntimeException
    • FullyQualifiedErrorId : 'C:\Users\username\Downloads\Weekly_system_report [en] (All Locations)-2024-07-25 13-37-03.xlsx' file not found

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.

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

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

  •                 throw "'$($Path)' file not found"
    
  •                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: ('C:\Users\usern... file not found:String) [], RuntimeException
    • FullyQualifiedErrorId : 'C:\Users\username\Downloads\2024_7_2023_Compliance_Report.xlsm' file not found
dfinke commented

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

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

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.

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.