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

Support the Import of Encrypted Excel Files #174

Closed
robinmalik opened this issue Mar 17, 2017 · 5 comments
Closed

Support the Import of Encrypted Excel Files #174

robinmalik opened this issue Mar 17, 2017 · 5 comments

Comments

@robinmalik
Copy link

robinmalik commented Mar 17, 2017

This code appears to work for me (assuming a plain text [string] parameter added to the Import-Excel function).

if($Password)
{
	$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage
	try
	{
		$xl.Load($Stream,$Password)
	}
	catch
	{
		$stream.Close()
		$stream.Dispose()
		$xl.Dispose()
		$xl = $null
		throw $_
	}
}
else
{
	$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
}

In the event that a bad password is specified, we get the error: Exception calling "Load" with "2" argument(s): "Invalid password".

Note: This is not the same as a password "protected" workbook or worksheet.

@dfinke
Copy link
Owner

dfinke commented Mar 17, 2017

@robinmalik Could you post a sample xlsx that is protected this way and let me know the password and steps to "unlock" it. Thanks.

May be a clue

http://epplus.codeplex.com/workitem/list/basic?field=CreationDate&direction=Descending&issuesToDisplay=Open&keywords=password&emailSubscribedItemsOnly=false

@robinmalik
Copy link
Author

This file has the ever so secure password of 'password': blah4.xlsx

Opening in Excel 2016 I'm prompted twice for a password. The above code seems to open the spreadsheet and import the workbook and worksheet data ok.

@SQLUnderworld
Copy link

The request for this support is a great idea! Thank you @robinmalik !

@DarkLite1
Copy link
Contributor

This is indeed a great request! I'll have a look when I have some time to add this feature to the newly updated Import-Excel. Thank you for the example. I'll use it for the test.

@robinmalik robinmalik changed the title Support the Import of Encypted Excel Files Support the Import of Encrypted Excel Files Sep 20, 2017
@DarkLite1
Copy link
Contributor

Fixed in #227
@dfinke this can be closed when the merge is successful

@dfinke dfinke closed this as completed Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants