Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import-Excel File Not Found string error #1618

Open
mealyman opened this issue Jul 26, 2024 · 7 comments
Open

Import-Excel File Not Found string error #1618

mealyman opened this issue Jul 26, 2024 · 7 comments

Comments

@mealyman
Copy link

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
@scriptingstudio
Copy link

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
Copy link

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
Copy link
Author

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
Copy link
Owner

dfinke commented Jul 29, 2024

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
Copy link
Author

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

@scriptingstudio
Copy link

scriptingstudio commented Jul 29, 2024

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants