Ask Your Question
0

How one can use Python to do computations on calc?

asked 2020-01-27 12:52:03 +0200

LearningLibre gravatar image

Can one use Python scripts in Libreoffice macros? I have Libreoffice calc 6.0.7.3 and Ubuntu 18.04. I installed libreoffice-script-provider-python. But how can I make some basic computation that tests if everything works? For example, if cell A1 contains value 1 and A2 contains value 2, then how can I compute (A1+A2)**4 via Python and put the value to the cell A3?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2020-01-27 16:40:22 +0200

mauricio gravatar image

Try:

doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.Sheets[0]

c1 = sheet['A1']
c2 = sheet['A2']
c3 = sheet['A3']

#If you wan calculate and set only value
c3.Value = (c1.Value + c2.Value) * 4

#If you want set formula
c3.Formula = '=(A1+A2)*4'
edit flag offensive delete link more

Comments

Thanks. I mean that where should I put that script such that I can control when to run it?

LearningLibre gravatar imageLearningLibre ( 2020-01-27 21:09:32 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-01-27 12:52:03 +0200

Seen: 82 times

Last updated: Jan 27