Page 1 of 1

[Solved] Editing text via macro

Posted: Fri Jul 21, 2017 7:22 pm
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.

Re: Editing text via macro

Posted: Fri Jul 21, 2017 8:19 pm
by RoryOF

Re: Editing text via macro

Posted: Fri Jul 21, 2017 8:25 pm
by FJCC

Code: Select all

oTextTables = ThisComponent.getTextTables()
oTbl1 = oTextTables.getByName("Table1")
oCellB2 = oTbl1.getCellByName("B2")
oCellB2.String = "Punto 1.6"

Re: Editing text via macro

Posted: Fri Jul 21, 2017 9:31 pm
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: