OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Delete text between two bookmarks using vb.net

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
AntonioRodrigo
Newbie
Newbie


Joined: 08 May 2012
Posts: 3

PostPosted: Tue May 08, 2012 4:10 am    Post subject: Delete text between two bookmarks using vb.net Reply with quote

Hello,

I am using Visual Studio 2010, Visual Basic.NET and Open Office 3.3 Writer.

I want to programmatically delete whole text between two bookmarks in writer document. My every document has a startHead and endHead bookmark - I need to delete everything in between those two bookmarks.

Any idea how to do this programmatically via .NET?



Greetings, Frenky



Moderation probe1: moved to MACROS AND API section, where all macro related questions belong to
Back to top
View user's profile Send private message
fjcc
General User
General User


Joined: 29 Apr 2012
Posts: 5

PostPosted: Tue May 08, 2012 5:34 pm    Post subject: Reply with quote

Perhaps code like this
Code:
Dim oSM                   'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API
Dim arg()
'Instanciate OOo : this line is mandatory with VB for OOo API
  Set oSM = CreateObject("com.sun.star.ServiceManager")
  Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
  openPath = "file:///C:/VB_Test.odt"
  Set oDoc = oDesk.loadComponentFromURL(openPath, "_blank", 0, arg())
  Set Bookmarks = oDoc.Bookmarks
  Set StartBM = Bookmarks.getByName("startHead")
  Set EndBM = Bookmarks.getByName("endHead")
  Set oCurs = oDoc.Text.createTextCursor()
  Set StartRange = StartBM.Anchor.Start
  Set EndRange = EndBM.Anchor.End
  oCurs.gotoRange StartRange, False
  oCurs.gotoRange EndRange, True
  oCurs.setString ("")
Back to top
View user's profile Send private message
AntonioRodrigo
Newbie
Newbie


Joined: 08 May 2012
Posts: 3

PostPosted: Tue May 08, 2012 9:57 pm    Post subject: Reply with quote

fjcc wrote:
Perhaps code like this
Code:
Dim oSM                   'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API
Dim arg()
'Instanciate OOo : this line is mandatory with VB for OOo API
  Set oSM = CreateObject("com.sun.star.ServiceManager")
  Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
  openPath = "file:///C:/VB_Test.odt"
  Set oDoc = oDesk.loadComponentFromURL(openPath, "_blank", 0, arg())
  Set Bookmarks = oDoc.Bookmarks
  Set StartBM = Bookmarks.getByName("startHead")
  Set EndBM = Bookmarks.getByName("endHead")
  Set oCurs = oDoc.Text.createTextCursor()
  Set StartRange = StartBM.Anchor.Start
  Set EndRange = EndBM.Anchor.End
  oCurs.gotoRange StartRange, False
  oCurs.gotoRange EndRange, True
  oCurs.setString ("")




This, my friend, had solved my problem. I've just slightly modified solution so it fits inside vb.net code. Thanks a lot.

Modified solution:

Dim oSM1 As Object = CreateObject("com.sun.star.ServiceManager")
Dim oDesk1 As Object = oSM1.createInstance("com.sun.star.frame.Desktop")
Dim openPath As String = "file:///C:/test.doc"
Dim oDoc1 = oDesk1.loadComponentFromURL(openPath, "_blank", 0, New unoidl.com.sun.star.beans.PropertyValue(0) {})
Dim Bookmarks As Object = oDoc1.Bookmarks
Dim StartBM As Object = Bookmarks.getByName("zacetekGlava")
Dim EndBM As Object = Bookmarks.getByName("konecGlava")
Dim oCurs As Object = oDoc1.Text.createTextCursor()
Dim StartRange As Object = StartBM.Anchor.Start
Dim EndRange As Object = EndBM.Anchor.End
oCurs.gotoRange(StartRange, False)
oCurs.gotoRange(EndRange, True)
oCurs.setString("")
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group