Closed theoami closed 2 years ago
Sorry, don't know what that is and have not looked to see if the EPPlus library supports it. Can you provide more detail on that and google EPPlus to see if that is supported?
Hello @dfinke ,
With Com Excel Application, I used this lines :
=> Worksheet protect :
$workbook.Worksheets("Sheet1").Protect('<password>',1,1,1,0,0,0,0,0,0,0,0,0,0,0,0);
=> Workbook structure protect :
$workbook.Protect('<password>',$true,$true);
With EEPlus library, I see this in the documentation but I'm not sure it's this :
//Lock the workbook totally
var workbook = package.Workbook;
workbook.Protection.LockWindows = true;
workbook.Protection.LockStructure = true;
Regards
Hello @theoami, this is what I have
$lcSetPassword = "123"
$xlPkg = Export-Excel -ExcelPackage $xlPkg -PassThru
for ($ii = 1; $ii -le $xlPkg.WorkBook.WorkSheets.Count; $ii++) {
$xlPkg.WorkBook.WorkSheets[$ii].Protection.SetPassword($lcSetPassword)
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowSelectLockedCells=$true
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowSelectUnlockedCells=$true
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowEditObject=$true
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowEditScenarios=$true
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowFormatCells=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowFormatColumns=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowFormatRows=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowInsertColumns=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowInsertRows=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowInsertHyperlinks=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowDeleteColumns=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowDeleteRows=$false
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowSort=$true
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowAutoFilter=$true
$xlPkg.WorkBook.WorkSheets[$ii].Protection.AllowPivotTables=$true
}
$xlPkg.WorkBook.Protection.LockStructure = $true
$xlPkg.WorkBook.Protection.LockWindows = $false
$xlPkg.WorkBook.Protection.LockRevision = $false
$xlPkg.WorkBook.Protection.SetPassword("$lcSetPassword")
$xlPkg.Save()
$xlPkg.Dispose()
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello,
I don't see methods in module for protect sheet and structure.
it's possible to add this functionnality ?
Regards