[Solved] Writing custom Document Property fields

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
jza
Posts: 239
Joined: Mon Nov 03, 2008 11:33 am
Location: Cancún, Mexico

[Solved] Writing custom Document Property fields

Post by jza »

Hi I want to know how can I write custom variables/values into a document, and also extract them. I was able to find the latter, but I am still a bit confused about inserting them.

I guess it doesnt make much sense to do this since these are permanents and once written, there is no need to re-fill them out.

However I want this to be dynamic from a different datasource.

Code: Select all

Sub GetMetaData
vDoc = ThisComponent
vInfo = vDoc.getDocumentInfo()
For i = 0 to vInfo.GetUserFieldCount() -1
  sKey = vInfo.GetUserFieldName(i)
  sVal = vInfo.GetUserFieldValue(i)
  s = s & Chr$(13) & "(" & sKey & "," & sVal & ")"
Next i
MsgBox s, 0, "User Fields"

End Sub
Having DocInfo also available through:

Code: Select all

  oPropValues() = ThisComponent.getDocumentInfo().getPropertyValues()
  MsgBox oPropValues(0).Value
This will give me the name of the Author. What I am missing is how to modify and re-submit the value from Basic.

Or Master fileds are worked with:

Code: Select all

oDoc = thisComponent
objField = oDoc.createInstance("com.sun.star.text.TextField.User")
sName = "com.sun.star.text.FieldMaster.User." + strVarName
Last edited by jza on Sun Sep 22, 2013 9:15 pm, edited 1 time in total.
AOO 4.1.1 on Arch Linux
User avatar
Zizi64
Volunteer
Posts: 11505
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Writing custom Document Property fields

Post by Zizi64 »

See:
http://forum.openoffice.org/en/forum/vi ... 20&t=39720
and
http://www.openoffice.org/api/docs/comm ... rties.html

Code: Select all

Sub setAuthorName

oDoc = ThisComponent
Info = oDoc.getDocumentInfo
Info.Author = "John Do"
'Info.ModifiedBy = "Captain Zero"
End Sub
Last edited by Zizi64 on Sun Sep 22, 2013 9:32 pm, edited 2 times in total.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
jza
Posts: 239
Joined: Mon Nov 03, 2008 11:33 am
Location: Cancún, Mexico

Re: Writing custom Document Property fields

Post by jza »

oh that was easy, I thought there was a special function to 'set' the values.

Thanks.
AOO 4.1.1 on Arch Linux
Post Reply