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

Close-ExcelPackage can't accept a null password with -SaveAs #1482

Open AndyTuke opened 1 year ago

AndyTuke commented 1 year ago

I have tried to write a script to remove passwords from Excel workbooks based on this sort of logic

$Password  = $null
$temp        = Open-ExcelPackage oldfile.xlsx -Password password1
Close-ExcelPackage -ExcelPackage $temp -SaveAs newfile.xlsx -Password $Password

If I supply no password parameter it saves the file with the original password as you'd expect If I supply a new password string it saves the file with that, again as you'd expect If I set $Password to equal $null or "" or '' no file is saved

Without this option how can I remove passwords from Excel workbooks

dfinke commented 1 year ago

Would've been surprised if that worked!

Never thought of supporting that, Remove-Password would be the function name.

Search for EPPlus and remove password. Let me know if you find something.

May be an easy way to use or add this as a feature.

AndyTuke commented 1 year ago

I assumed it would be easy, and read this post https://stackoverflow.com/questions/42860894/remove-known-excel-passwords-with-powershell where one response states that he used ImportExcel to achieve it. Wondering what he did. I found a hefty price tag on EPPlus ...

dfinke commented 1 year ago

yeah that is v5|v7 of EPPlus. This module uses v4.x of EPPlus. They may have had a solution or workaround.

The solution looks like what I was going to suggest off the top of my head and has nothing really to do with the module.

It uses Import-Excel to read the xlsx and then Export-Excel to save it to another file without a password.

👉 NOTE: Import-Excel only reads the data, no formatting etc, etc, etc