[Solved] Editing text via macro

Creating a macro - Writing a Script - Using the API

[Solved] Editing text via macro

Postby KAOS » Fri Jul 21, 2017 7:22 pm

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   Expand viewCollapse view
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
KAOS
 
Posts: 6
Joined: Fri Jul 21, 2017 6:52 pm

Re: Editing text via macro

Postby RoryOF » Fri Jul 21, 2017 8:19 pm

Apache OpenOffice 4.1.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25044
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Editing text via macro

Postby FJCC » Fri Jul 21, 2017 8:25 pm

Code: Select all   Expand viewCollapse view
oTextTables = ThisComponent.getTextTables()
oTbl1 = oTextTables.getByName("Table1")
oCellB2 = oTbl1.getCellByName("B2")
oCellB2.String = "Punto 1.6"
AOO 3.4 or 4.1 on MS Windows XP ( before 2013-08-03) or Windows 7
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 6024
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Editing text via macro

Postby KAOS » Fri Jul 21, 2017 9:31 pm

FJCC wrote:
Code: Select all   Expand viewCollapse view
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
KAOS
 
Posts: 6
Joined: Fri Jul 21, 2017 6:52 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 12 guests