Ask Your Question

How do I find and replace many variable at once?

asked 2018-03-05 01:14:12 +0200

ddelma2 gravatar image

Having a text like A B C D... I would like to replace let's say A -> 1, B ->2 etc. The number of patterns to be changed is high. That's why I would like to instruct LibreOffice to do it, but how?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-03-05 15:43:25 +0200

Jim K gravatar image

updated 2018-03-05 15:55:12 +0200

Here is a Python macro that works in both Writer and Calc. Use APSO to make it easier to create and run Python macros.

def replace_multiple():
    oDoc = XSCRIPTCONTEXT.getDocument()
    if oDoc.supportsService(""):
    elif oDoc.supportsService(""):
        for oSheet in oDoc.getSheets():

def replace_multiple_in(xReplaceable):
    # Note: If replacement strings are irregular, use a Python dictionary instead of 'ABCD'.
    for letter in 'ABCD':
        oReplace = xReplaceable.createReplaceDescriptor()
        oReplace.setReplaceString(ord(letter) - ord('A') + 1)
        oReplace.SearchRegularExpression = True

g_exportedScripts = replace_multiple,
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-03-05 01:14:12 +0200

Seen: 63 times

Last updated: Mar 05 '18