[Solved] Set a range with 1 parameter as variable

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
maximlee
Posts: 2
Joined: Mon Jan 15, 2018 3:39 am

[Solved] Set a range with 1 parameter as variable

Post by maximlee »

Hi,
I am trying to insert a formula to every row, calculating sum of several cells in the same row. By the moment of automatic insertion I will only know columns, while row numbers would be variable, so I need to add something like:

[A0] = [SUM(N0:T0)]
[A1] = [SUM(N1:T1)]

Code: Select all

oSheet.getCellByPosition(myCol, j).formula = "=SUM("N" & j & ":T" & j)"
What's the right syntax?
Last edited by maximlee on Tue Jan 16, 2018 2:02 am, edited 2 times in total.
Libre Office 5.2 on Windows 7
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set a range with 1 parameter as variable

Post by FJCC »

The code would be like

Code: Select all

oSheet.getCellByPosition(myCol, j).formula = "=SUM(N" & j & ":T" & j & ")"
but j cannot be 0 because cell addresses like N0 are not valid.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Set a range with 1 parameter as variable

Post by UnklDonald418 »

Try

Code: Select all

 oSheet.getCellByPosition(myCol, j).setFormula ( "=SUM(N" & j & ":T" & j & ")")
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
maximlee
Posts: 2
Joined: Mon Jan 15, 2018 3:39 am

Re: [Solved] Set a range with 1 parameter as variable

Post by maximlee »

Thanks, this is it (at least the 1st entry).
Libre Office 5.2 on Windows 7
Post Reply