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

Table cursor not moving correctly

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


Joined: 21 Sep 2010
Posts: 28

PostPosted: Tue Apr 24, 2012 2:10 pm    Post subject: Table cursor not moving correctly Reply with quote

Hi,

I have written code to parse through the tables in the doc and add caption on top of the table matching with the table name. But the problem is that its only being done to the first table and all other tables dont get the captions added.

Any help is appreciated

Code:

Sub ADD_TABLE_CAPTION
On Error Resume Next

        oDoc = ThisComponent 'get the document that called the macro
                     
        for i = 0 to oDoc.getTextTables().Count() - 1
       
        Dim oTab
        Dim oVCurs
       
        oTab = oDoc.getTextTables().getByIndex(i)
        print "Table name" & oTab.getName()
       Tname = oTab.getName()
    
       oDoc.getCurrentController().select(oTab)
       oVCurs = oDoc.getCurrentController().getViewCursor()
       oVCurs.goLeft(1, False)
      
       rem ----------------------------------------------------------------------
      rem define variables
      dim document   as object
      dim dispatcher as object
      
      rem ----------------------------------------------------------------------
      rem get access to the document
      document   = oDoc.CurrentController.Frame
      dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 
      
      rem ----------------------------------------------------------------------
      dim args3(0) as new com.sun.star.beans.PropertyValue
      args3(0).Name = "Text"
      args3(0).Value = Tname

      dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args3())
                       
      next i
      
End Sub
Back to top
View user's profile Send private message
DVezina
OOo Advocate
OOo Advocate


Joined: 29 Sep 2006
Posts: 248
Location: Orlando

PostPosted: Wed May 02, 2012 9:20 am    Post subject: Reply with quote

I've never been able to make ViewCursor and dispatcher work together. In my experience, it's best to use as little of dispatcher as possible. Instead use the methods and properties available for the object.


Code:

Sub ADD_TABLE_CAPTION
On Error Resume Next
   Dim oTab
   Dim oVCurs

   oDoc = ThisComponent 'get the document that called the macro'
   oVCurs = oDoc.getCurrentController().getViewCursor()
   ' go to start of document '
   oVCurs.GoToStart()
 
                     
   for i = 0 to oDoc.getTextTables().Count() - 1
       
      oTab = oDoc.getTextTables().getByIndex(i)
      Tname = oTab.getName()
      oController = oDoc.getCurrentController().select(oTab)
   
      oVCurs = oDoc.getCurrentController().getViewCursor()
      oVCurs.goLeft(1, False)
      oVCurs.setString(Tname)        
   next i
       
End Sub
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