[Solved] Editing text via macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
KAOS
Posts: 6
Joined: Fri Jul 21, 2017 6:52 pm

[Solved] Editing text via macro

Post by KAOS »

Hi,
I have very basic problem, which I am worried will have very complicated solution. I know only basics about programming so I understand all kind of functions and conditions and stuff. To my problem -
I have a document in OO writer Which contains some textfields and two tables. In one table are two columns and ten rows. First is column is name and second is model.
For example - first is "Fiat" second could be "Bravo 1.2". What I need is macro, to delete "Bravo 1.2" and write instead "Punto 1.6". I cannot find the way how to properly address that one column which I want to change. (it is of course more complicated because first I need to find out in simple .txt file full of crazy text all the proper "models", and in reality it is not even about cars, then I save it into variable and then I need to write it in that column, but that is what I have not problem to do)
I can imagine the solution should be something like (alert - it is not real code, just like a quick sketch):

Code: Select all

Dim column1 as object
Dim sModel1 as string
sModel1="Punto 1.6"
Column1 = ThisDocument.getTableByName("table1").getColumnByName("B2")
Column1.Value = "Punto 1.6"
'delete anything in B2 and write Punto 1.6
And I repeat it is in writer and it has to stay that way.

Thank you for any effort to help me.
Last edited by RoryOF on Fri Jul 21, 2017 11:19 pm, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
OpenOffice 4.1.3
Windows 10
User avatar
RoryOF
Moderator
Posts: 34611
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Editing text via macro

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
FJCC
Moderator
Posts: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Editing text via macro

Post by FJCC »

Code: Select all

oTextTables = ThisComponent.getTextTables()
oTbl1 = oTextTables.getByName("Table1")
oCellB2 = oTbl1.getCellByName("B2")
oCellB2.String = "Punto 1.6"
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.
KAOS
Posts: 6
Joined: Fri Jul 21, 2017 6:52 pm

Re: Editing text via macro

Post by KAOS »

FJCC wrote:

Code: Select all

oTextTables = ThisComponent.getTextTables()
oTbl1 = oTextTables.getByName("Table1")
oCellB2 = oTbl1.getCellByName("B2")
oCellB2.String = "Punto 1.6"
Thank you very much, that was exactly what I needed. I just wonder how is possible that I was not able to find it anywhere. I guess I still have a lot to learn about search engine. :super:
OpenOffice 4.1.3
Windows 10
Post Reply