mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-20 02:03:29 +00:00
fix naming consitency (case mostly)
This commit is contained in:
55
ExportedCommands/Set-WorksheetProtection.ps1
Normal file
55
ExportedCommands/Set-WorksheetProtection.ps1
Normal file
@@ -0,0 +1,55 @@
|
||||
Function Set-WorksheetProtection {
|
||||
[Cmdletbinding()]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')]
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
|
||||
[switch]$IsProtected,
|
||||
[switch]$AllowAll,
|
||||
[switch]$BlockSelectLockedCells,
|
||||
[switch]$BlockSelectUnlockedCells,
|
||||
[switch]$AllowFormatCells,
|
||||
[switch]$AllowFormatColumns,
|
||||
[switch]$AllowFormatRows,
|
||||
[switch]$AllowInsertColumns,
|
||||
[switch]$AllowInsertRows,
|
||||
[switch]$AllowInsertHyperlinks,
|
||||
[switch]$AllowDeleteColumns,
|
||||
[switch]$AllowDeleteRows,
|
||||
[switch]$AllowSort,
|
||||
[switch]$AllowAutoFilter,
|
||||
[switch]$AllowPivotTables,
|
||||
[switch]$BlockEditObject,
|
||||
[switch]$BlockEditScenarios,
|
||||
[string]$LockAddress,
|
||||
[string]$UnLockAddress
|
||||
)
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('isprotected') -and $IsProtected -eq $false) {$worksheet.Protection.IsProtected = $false}
|
||||
elseif ($IsProtected) {
|
||||
$worksheet.Protection.IsProtected = $true
|
||||
foreach ($ParName in @('AllowFormatCells',
|
||||
'AllowFormatColumns', 'AllowFormatRows',
|
||||
'AllowInsertColumns', 'AllowInsertRows', 'AllowInsertHyperlinks',
|
||||
'AllowDeleteColumns', 'AllowDeleteRows',
|
||||
'AllowSort' , 'AllowAutoFilter', 'AllowPivotTables')) {
|
||||
if ($AllowAll -and -not $PSBoundParameters.ContainsKey($Parname)) {$worksheet.Protection.$ParName = $true}
|
||||
elseif ($PSBoundParameters[$ParName] -eq $true ) {$worksheet.Protection.$ParName = $true}
|
||||
}
|
||||
if ($BlockSelectLockedCells) {$worksheet.Protection.AllowSelectLockedCells = $false }
|
||||
if ($BlockSelectUnlockedCells) {$worksheet.Protection.AllowSelectUnLockedCells = $false }
|
||||
if ($BlockEditObject) {$worksheet.Protection.AllowEditObject = $false }
|
||||
if ($BlockEditScenarios) {$worksheet.Protection.AllowEditScenarios = $false }
|
||||
}
|
||||
Else {Write-Warning -Message "You haven't said if you want to turn protection off, or on." }
|
||||
|
||||
if ($LockAddress) {
|
||||
Set-ExcelRange -Range $Worksheet.cells[$LockAddress] -Locked
|
||||
}
|
||||
elseif ($IsProtected) {
|
||||
Set-ExcelRange -Range $Worksheet.Cells -Locked
|
||||
}
|
||||
if ($UnlockAddress) {
|
||||
Set-ExcelRange -Range $Worksheet.cells[$UnlockAddress] -Locked:$false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user