How to protect worksheet using com object
I am looking to programmatically set the protect worksheet and set password. If anyone can give me a few pointers.
First time here? Check out the FAQ!
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(<password>) and .Unprotect(<password>) of object Sheet has one parameter <password> 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
Asked: 2016-03-14 01:40:44 +0100
Seen: 118 times
Last updated: Mar 15 '16
How do I export a chart in an image format from LibreOffice Calc? [closed]
Are there plans for a "papercut" project for libreoffice [closed]
Is it normal for Calc goal seek to take very long? [closed]
Please refine "Search" in Calc - implement functions in Gnumeric [closed]
LibreOffice Calc will not link to external data via internet [closed]
Is there a LibreOffice .odt, .ods viewer for Android? [closed]
Why is Calc so much slower at opening/saving files than MS-Office? (win7 x64) [closed]