ImportExcel icon indicating copy to clipboard operation
ImportExcel copied to clipboard

Export-Excel with -Password failed with error

Open limcheepei opened this issue 3 years ago • 7 comments

When I tried to create Excel file using Export-Excel with -Password "Test1234!", there was an error message as below. catch { throw "Could not open Excel Package $path" }

Need help on how to set this -Password parameter. Module version is 7.8.4

Removing the -Password parameter was able to create the file successfully without any password.

limcheepei avatar Jun 13 '23 02:06 limcheepei

Please post the versions are running and the environment.

dfinke avatar Jun 13 '23 16:06 dfinke

How do I check the ABE? I am running Windows 10.

I tried with this example (running PowerShell 7 as administrator)

PS C:\Users\lcp> $data | Export-Excel .\salesData.xlsx -Password 'test' Exception: C:\Users\lcp\Documents\PowerShell\Modules\ImportExcel\7.8.4\Public\Export-Excel.ps1:126 Line | 126 | catch { throw "Could not open Excel Package $path" } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Could not open Excel Package .\salesData.xlsx

limcheepei avatar Jun 14 '23 00:06 limcheepei

what is in $data?

dfinke avatar Jun 14 '23 02:06 dfinke

PS C:\Users\lcp> $data

Region State Units Price


West Texas 927 923.71 North Tennessee 466 770.67 East Florida 520 458.68 East Maine 828 661.24 West Virginia 465 053.58 North Missouri 436 235.67 South Kansas 214 992.47 North North Dakota 789 640.72 South Delaware 712 508.55

Here is another info.

PS C:\Users\lcp> $data | Export-Excel .\salesData.xlsx -Password 'test' MethodInvocationException: C:\Users\lcp\Documents\PowerShell\Modules\ImportExcel\7.8.4\Public\Export-Excel.ps1:679 Line | 679 | if ($Password) { $pkg.Save($Password) } | ~~~~~~~~~~~~~~~~~~~~ | Exception calling "Save" with "1" argument(s): "Error saving file C:\Users\lcp\salesData.xlsx"

limcheepei avatar Jun 14 '23 02:06 limcheepei

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 Aug 12 '23 13:08 stale[bot]

@dfinke Any update on this fix. I tried again with the following command, and encountered the same error.

Get-Process | Export-Excel -Path C:\Temp\Processes.xlsx -Password "abc"

MethodInvocationException: C:\Users\lcp\Documents\PowerShell\Modules\ImportExcel\7.8.4\Public\Export-Excel.ps1:679 Line | 679 | if ($Password) { $pkg.Save($Password) } | ~~~~~~~~~~~~~~~~~~~~ | Exception calling "Save" with "1" argument(s): "Error saving file C:\Temp\Processes.xlsx"

limcheepei avatar Feb 26 '24 01:02 limcheepei

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 05:04 stale[bot]