I am looking to programmatically set the protect worksheet and set password. If anyone can give me a few pointers.
See subroutines ProtectSheets() and UnprotectSheets() in standard library Tools module Misc.
Methods .Protect() and .Unprotect() of object Sheet has one parameter as String.
Works Perfectly. Cheers. John sun
Written In VB.net
not complete code
Dim oSM As Object = CreateObject("com.sun.star.ServiceManager")
Dim oMM As Object = oSM.createInstance("com.sun.star.frame.Desktop")
Private WorkSheet As Object
Dim OpenPar(1) As Object
OpenPar(0) = MakePropertyValue("Hidden", True)
Spreadsheet = oMM.LoadComponentFromUrl("file:///'Location'/" & SpreadSheetName, "_blank", 0, OpenPar)
WorkSheet = Spreadsheet.Sheets.getByName(WorkSheetName)
WorkSheet.unprotect("password")
'Do something with worksheet'
WorkSheet.protect("password")
Dim arg(-1) As Object
Spreadsheet.storetoURL("file:///'Location'/" & SaveName, arg)
Spreadsheet.Close(False)
Function MakePropertyValue(cName, uValue) As Object
Dim oPropertyValue As Object
Dim oSM As Object
oSM = CreateObject("com.sun.star.ServiceManager")
oPropertyValue = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oPropertyValue.Name = cName
oPropertyValue.Value = uValue
MakePropertyValue = oPropertyValue
End Function