[Solved] Can't change a bookmarked word in a table in Writer

Creating a macro - Writing a Script - Using the API

[Solved] Can't change a bookmarked word in a table in Writer

Postby zenira » Thu Mar 09, 2017 9:51 pm

Hi
I can change word outside in table but can't change inside in table in Writer Document.
This code works
Image
Code: Select all   Expand viewCollapse view
Sub ChangeWord
dim oDoc as object
dim oVal()
dim Bookmarks,oAnchor,oCurs as object
url="D:\work.odt"
oDoc=StarDesktop.LoadComponentFromURL(ConvertToURL(url),"_blank",0,oVal())
Bookmarks=oDoc.getBookmarks()
oAnchor = Bookmarks.getByName("Dog").getAnchor()
oCurs = oDoc.getCurrentController().getViewCursor()
oCurs.gotoRange(oAnchor, False)
oCurs.String ="Cad"
End Sub


But when I move the "Dog" word into a table, code does not change it to "Cad"
Image
Code: Select all   Expand viewCollapse view
Sub ChangeWord
dim oDoc as object
dim oVal()
dim Bookmarks,oAnchor,oCurs as object
dim oTable as object
url="D:\work.odt"
oDoc=StarDesktop.LoadComponentFromURL(ConvertToURL(url),"_blank",0,oVal())
Bookmarks=oDoc.getBookmarks()
oAnchor = Bookmarks.getByName("Dog").getAnchor()
oCurs = oDoc.getCurrentController().getViewCursor()
oCurs.gotoRange(oAnchor, False)
oCurs.String ="Cad"
End Sub


Thanks for your help
Last edited by Hagar Delest on Sun Mar 12, 2017 12:57 pm, edited 1 time in total.
Reason: tagged [Solved].
LibreOffice 4.1.0.4 on Windows 7
zenira
 
Posts: 85
Joined: Sun May 11, 2014 11:24 am

Re: Why I can't change a bookmarked word in a table in Write

Postby FJCC » Thu Mar 09, 2017 10:22 pm

I see the same problem in OpenOffice. As an alternative, this seems to work
Code: Select all   Expand viewCollapse view
Bookmarks=oDoc.getBookmarks()
oAnchor = Bookmarks.getByName("Dog").getAnchor()
oAnchor.String = "Cad"
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: 6026
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Why I can't change a bookmarked word in a table in Write

Postby zenira » Fri Mar 10, 2017 11:36 pm

Oh thank you FJCC. But what is different with oCurs and without oCurs?
LibreOffice 4.1.0.4 on Windows 7
zenira
 
Posts: 85
Joined: Sun May 11, 2014 11:24 am

Re: [Solved] Can't change a bookmarked word in a table in Wr

Postby Hagar Delest » Sun Mar 12, 2017 1:09 pm

The tables are special objects in Writer and I think that if you want to go that way (with a cursor), you need to handle the text first and then the tables. Whereas changing the content by the .String command is more straightforward.
Since the Bookmarks array allows you to edit its entries, no need of a cursor.
AOO 4.1.4 RC2 on Xubuntu 17.04, (Zesty Zapus) and 4.1.3 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 27637
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Can't change a bookmarked word in a table in Wr

Postby zenira » Mon Mar 13, 2017 8:45 pm

Thank you Hagar Delest
LibreOffice 4.1.0.4 on Windows 7
zenira
 
Posts: 85
Joined: Sun May 11, 2014 11:24 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 12 guests