| View previous topic :: View next topic |
| Author |
Message |
newlearner General User

Joined: 21 Sep 2010 Posts: 28
|
Posted: Tue Apr 24, 2012 2:10 pm Post subject: Table cursor not moving correctly |
|
|
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 |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Wed May 02, 2012 9:20 am Post subject: |
|
|
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 |
|
 |
|