[Solved] To close [Writer] doc as read only, from macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

[Solved] To close [Writer] doc as read only, from macro

Post by misitu »

Hello...

I would like to be able to close an Open Office [writer] doc protected, as in the gui selection file>properties>security>open file read-only, only from a macro.

At the moment as a workround I use SetAttr. However this makes a hard coded Read Only, as in the [windows] properties box. I really only wanted a simple status setting, reversible when opening the document afterwards.

I was experimenting with args(N).Name="ReadOnly", args(N).Value="True" but this is more or less guesswork as there doesn't SEEM to be a more appropriate tag in the documentation.

Do any of the experts have a clue for me?

For the avoidance of doubt, experimental working code follows

Code: Select all

REM  *****  BASIC  *****

Sub Main
	saveAndClose("TEST", "outlook", "abracadabra")
End Sub
sub saveAndClose (sysInstance as string, basicLibrary as string, basicModule as string)
	Dim storeAsUrl As String
	Dim storeToUrl As String
	dim whereToStore as string
	whereToStore = sysInstance & "/" & basicLibrary & "/" & basicModule
'														store as C:/Users/Public/Bookkeeping/LIVE/forexCharts/basicLibrary/basicModule.odt
	Dim args_ODS(0) As New com.sun.star.beans.PropertyValue
'	dim args_ODS(1) as new com.sun.star.beans.PropertyValue
	storeAsUrl = "file:///C:/Users/Public/Bookkeeping/" & whereToStore & ".odt"
	args_ODS(0).Name = "Overwrite"
	args_ODS(0).Value = True
'	args_ODS(1).Name = "ReadOnly"
'	args_ODS(1).Value = "True"
	ThisComponent.storeAsURL(storeAsUrl, args_ODS())
	SetAttr(storeAsUrl,1)
	ThisComponent.close(true)
End Sub
Thanks in advance, one way or the other
David
Last edited by misitu on Fri Feb 24, 2017 6:18 pm, edited 1 time in total.
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: To close [writer] doc as read only, from macro

Post by misitu »

I've solved this problem.

Need to add the following to the storeAsUrl args

Code: Select all

.Name = "UpdateDocMode"
.Value = "NO_UPDATE"
Caution! this only works after the file is CLOSED. On reopening, the toolbar shows the edit button flat (click to go to edit). HOWEVER, without closing the file, the UpdateDocMode is not applied, even though the file has been Stored. A bit puzzling ...

Hope this helps. Another twisty little maze of passages, some different (TM)

David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
Post Reply