Page 1 of 1

[Solved] Writing custom Document Property fields

Posted: Wed Sep 18, 2013 11:44 pm
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

Re: Writing custom Document Property fields

Posted: Sun Sep 22, 2013 9:13 pm
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

Re: Writing custom Document Property fields

Posted: Sun Sep 22, 2013 9:14 pm
by jza
oh that was easy, I thought there was a special function to 'set' the values.

Thanks.