Skip to content

Support the Import of Encrypted Excel Files #174

@robinmalik

Description

@robinmalik

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions