Page 1 of 1

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

Posted: Thu Mar 09, 2017 9:51 pm
by zenira
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

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

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

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

Posted: Thu Mar 09, 2017 10:22 pm
by FJCC
I see the same problem in OpenOffice. As an alternative, this seems to work

Code: Select all

 Bookmarks=oDoc.getBookmarks()
oAnchor = Bookmarks.getByName("Dog").getAnchor()
oAnchor.String = "Cad"

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

Posted: Fri Mar 10, 2017 11:36 pm
by zenira
Oh thank you FJCC. But what is different with oCurs and without oCurs?

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

Posted: Sun Mar 12, 2017 1:09 pm
by Hagar Delest
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.

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

Posted: Mon Mar 13, 2017 8:45 pm
by zenira
Thank you Hagar Delest