Ask Your Question
1

Calc: How to Find and Replace with Python

asked 2016-07-15 16:34:36 +0200

elsi gravatar image

Hello Officers!

I'm in desperate need of your help. Since yesterday I try to code a Find and Replace macro (+ Regular Expressions) with Python.

I want to find ".+" and replace it with "&".

That's what I have up to now:

def search():

document = XSCRIPTCONTEXT.getDocument()
ctx = uno.getComponentContext()
sm = ctx.ServiceManager
dispatcher = sm.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
sheet = document.Sheets.getByIndex(0)

replace = sheet.createReplaceDescriptor()
replace.SearchRegularExpression = True
replace.SearchString = ".+"
replace.ReplaceString ="&"
return None

Unfortunately, it happens absolutely nothing.

I'm happy and thankful for every little hint, code example and idea.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-07-16 17:08:57 +0200

mauricio gravatar image

In Calc, if you use regular expression, the ampersand (&) mean, replace with the same value found.

Try with this code: https://gitlab.com/snippets/22593

Test with some different values in replace and see result.

Best regards

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-15 16:34:36 +0200

Seen: 481 times

Last updated: Jul 16 '16