[Solved] Insert formula with quotation marks into cell

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
MATT.B
Posts: 165
Joined: Tue Nov 18, 2014 2:16 am

[Solved] Insert formula with quotation marks into cell

Post by MATT.B »

im having a bit of trouble with this bit of code
the objective is to use a macro to merger cells AG22-AH22 (COMPLETED) but when i try to put the formula "=CELL("CONTENTS";$PAGE_4.AC18)" into a cell i get an error about parenthesis. i even tried something like the below code but got a syntax error

Code: Select all

oCells = oSheet.getCellrangeByname("AG22:AH22")
	oCell = oSheet.getCellRangeByName("AG22")
	oCells.merge(True)
	oCell.setformula("=CELL("CONTENTS";$PAGE_4.AC18)")
i also tried

Code: Select all

oCells = oSheet.getCellrangeByname("AG22:AH22")
	oCell = oSheet.getCellRangeByName("AG22")
	oCells.merge(True)
	myformula = "=CELL("CONTENTS";$PAGE_4.AC18)"
        oCell.setformula(myformula)
not sure what i did wrong in this
Last edited by MATT.B on Wed Dec 18, 2019 1:40 am, edited 1 time in total.
OpenOffice 4.1.1 ON WINDOWS 7 64
FJCC
Moderator
Posts: 9539
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Trying to insert formula into cell with macro

Post by FJCC »

The quotation marks inside of your formula are causing the problem. Try

Code: Select all

 oCell.setformula("=CELL(""CONTENTS"";$PAGE_4.AC18)")
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.
Rotnbair
Posts: 12
Joined: Wed Aug 23, 2023 10:01 pm

Re: [Solved] Insert formula with quotation marks into cell

Post by Rotnbair »

Thanks, oCell.setformula() is exactly what I needed! Via a forum seaerch I am nearly always able to find things like this, including locating the Active Cell with

oCell = oSheet.getCellByPosition(ACcol,ACrow)

Is there a manual somewhere that contains all the oCell & oSheet structures, etc.?
Apache OpenOffice 4.1.14
Windows 11
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Insert formula with quotation marks into cell

Post by JeJe »

The API is here

https://www.openoffice.org/api/docs/com ... le-ix.html

https://www.openoffice.org/api/docs/com ... le-ix.html

Take a look at Pitonyak's OpenOffice Macro Information guides

https://www.pitonyak.org/oo.php

If you use MRI you can see what properties and methods are available for any object

viewtopic.php?t=49294
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply