ImportExcel icon indicating copy to clipboard operation
ImportExcel copied to clipboard

Import-Excel File Not Found string error

Open mealyman opened this issue 1 year ago • 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

mealyman avatar Jul 26 '24 15:07 mealyman

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 avatar Jul 26 '24 17:07 scriptingstudio

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

scriptingstudio avatar Jul 27 '24 17:07 scriptingstudio

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

mealyman avatar Jul 29 '24 12:07 mealyman

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

dfinke avatar Jul 29 '24 14:07 dfinke

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

mealyman avatar Jul 29 '24 14:07 mealyman

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.

scriptingstudio avatar Jul 29 '24 16:07 scriptingstudio

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.

mealyman avatar Jul 29 '24 22:07 mealyman

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 04:04 stale[bot]