mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Added Protect-Worksheet Tests
This commit is contained in:
37
__tests__/ProtectWorksheet.tests.ps1
Normal file
37
__tests__/ProtectWorksheet.tests.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
$path = "$Env:TEMP\test.xlsx"
|
||||
Remove-Item -path $path -ErrorAction SilentlyContinue
|
||||
$excel = ConvertFrom-Csv @"
|
||||
Product, City, Gross, Net
|
||||
Apple, London , 300, 250
|
||||
Orange, London , 400, 350
|
||||
Banana, London , 300, 200
|
||||
Orange, Paris, 600, 500
|
||||
Banana, Paris, 300, 200
|
||||
Apple, New York, 1200,700
|
||||
|
||||
"@ | Export-Excel -Path $path -WorksheetName Sheet1 -PassThru
|
||||
|
||||
$ws = $excel.sheet1
|
||||
|
||||
Set-WorkSheetProtection -WorkSheet $ws -IsProtected -BlockEditObject -AllowFormatRows -UnLockAddress "1:1"
|
||||
|
||||
Close-ExcelPackage -ExcelPackage $excel
|
||||
|
||||
Describe "Setting worksheet protection " {
|
||||
BeforeAll {
|
||||
$excel = Open-ExcelPackage -Path $path
|
||||
$ws = $ws = $excel.sheet1
|
||||
}
|
||||
it "Turned on protection for the sheet " {
|
||||
$ws.Protection.IsProtected | should be $true
|
||||
}
|
||||
it "Set sheet-wide protection options " {
|
||||
$ws.Protection.AllowEditObject | should be $false
|
||||
$ws.Protection.AllowFormatRows | should be $true
|
||||
$ws.cells["a2"].Style.Locked | should be $true
|
||||
}
|
||||
it "Unprotected some cells " {
|
||||
$ws.cells["a1"].Style.Locked | should be $false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user