mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Fix broken test & regression re: passwords
This commit is contained in:
@@ -347,8 +347,9 @@ function Import-Excel {
|
||||
process {
|
||||
if ($path) {
|
||||
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'
|
||||
if ($Password) {$ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream , $Password }
|
||||
else {$ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream}
|
||||
$ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage
|
||||
if ($Password) { $ExcelPackage.Load($stream,$Password)}
|
||||
else { $ExcelPackage.Load($stream) }
|
||||
}
|
||||
try {
|
||||
#Select worksheet
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#Requires -Modules Pester
|
||||
Import-Module $PSScriptRoot\..\ImportExcel.psd1 -Force
|
||||
if ($PSVersionTable.PSVersion.Major -gt 5) { Write-Warning "Can't test grid view on V6" }
|
||||
if ($PSVersionTable.PSVersion.Major -gt 5) { Write-Warning "Can't test grid view on V6 and later" }
|
||||
else {Add-Type -AssemblyName System.Windows.Forms }
|
||||
Describe "Compare Worksheet" {
|
||||
Context "Simple comparison output" {
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
Describe "Password Support" {
|
||||
Context "Password protected sheet" {
|
||||
BeforeAll {
|
||||
$password = "YouMustRememberThis"
|
||||
$path = "$env:TEMP\Test.xlsx"
|
||||
if ($PSVersionTable.PSVersion.Major -GT 5) {
|
||||
Write-Warning "Can't test passwords on V6 and later"
|
||||
return
|
||||
}
|
||||
|
||||
Describe "Password Support" {
|
||||
Context "Password protected sheet" {
|
||||
BeforeAll {
|
||||
$password = "YouMustRememberThis"
|
||||
$path = "$env:TEMP\Test.xlsx"
|
||||
Remove-Item $path -ErrorAction SilentlyContinue
|
||||
Get-Service | Select-Object -First 10 | Export-excel -password $password -Path $Path -DisplayPropertySet
|
||||
Get-Service | Select-Object -First 10 | Export-excel -password $password -Path $Path -DisplayPropertySet
|
||||
}
|
||||
it "Threw an error when the password was omitted " {
|
||||
{Open-ExcelPackage -Path $path } | should throw
|
||||
}
|
||||
it "Was able to append when the password was included " {
|
||||
{Get-Service | Select-Object -First 10 |
|
||||
{Get-Service | Select-Object -First 10 |
|
||||
Export-excel -password $password -Path $Path -Append } | should not throw
|
||||
}
|
||||
it "Kept the password on the file when it was saved " {
|
||||
{Import-Excel $Path } | should throw
|
||||
{Import-Excel $Path } | should throw
|
||||
}
|
||||
it "Could read the file when the password was included " {
|
||||
(import-excel $path -Password $password).count | should be 20
|
||||
it "Could read the file when the password was included " {
|
||||
(import-excel $path -Password $password).count | should be 20
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user