Add text to "Author" field without replacing existing text

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
fracture62
Posts: 1
Joined: Tue Dec 01, 2020 1:12 pm

Add text to "Author" field without replacing existing text

Post by fracture62 »

Hello,

so I am running a script that processes a document and sets certain text inside the author field, for that I use:

Code: Select all

oDoc.getDocumentProperties().Author = cPrintText
however some documents have pre-existing text in the author field, and this will overwrite it.

How would I go about keeping the existing text in the field and just adding the wanted text to it?
Open Office 3.3 + Windows 10
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Add text to "Author" field without replacing existing te

Post by RoryOF »

Have your code read the existing text, then append the new to it and write it back.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2777
Joined: Wed Mar 09, 2016 2:40 pm

Re: Add text to "Author" field without replacing existing te

Post by JeJe »

That's done with &

Assuming you want a space " " between old and new

Code: Select all

oDoc.getDocumentProperties().Author =  oDoc.getDocumentProperties().Author & " " & cPrintText
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply