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

[Solved] Spot a ReferenceMark in a table (Writer document )

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


Joined: 06 Feb 2006
Posts: 5164
Location: France

PostPosted: Tue Dec 19, 2006 5:56 am    Post subject: [Solved] Spot a ReferenceMark in a table (Writer document ) Reply with quote

I've a piece of code to check if a selection has been referenced as a ReferenceMark.
Code:
         oPortionEnum = oTextElement.createEnumeration
         do while oPortionEnum.hasMoreElements
            oPortion = oPortionEnum.nextElement
            if oPortion.TextPortionType = "ReferenceMark" then
               msgbox "Bingo"
               exit do
            end if
         loop

It works well for text in ... main text (If oTextElement.supportsService("com.sun.star.text.Paragraph") ). But is there a way to check it also when the ReferenceMark is inside a table cell (of a Writer document) ? Or do I have to create a new Enumeration ?

I'm stuck here :
Code:
If oTextElement.SupportsService("com.sun.star.text.TextTable") then 'If table...
    rows = oTextElement.getRows().count 'Prepare to iterate through it.
    cols = oTextElement.getColumns().count
    For r = 0 to rows - 1 'Iterate.
        For c = 0 to cols - 1
          Cell = oTextElement.getCellByPosition(c,r)
          elementCursor = Cell.createTextCursor

_________________
Now on the EN user community forum


Last edited by Hagar Delest on Wed Dec 20, 2006 1:41 am; edited 1 time in total
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Dec 19, 2006 7:43 am    Post subject: Reply with quote

Here's my effort to enumerate both text and table portions:
Code:
Sub MainEnumerator
MainEnum = ThisComponent.Text.createEnumeration
While MainEnum.hasMoreElements
 thisMain = MainEnum.nextElement
 If Not thisMain.SupportsService("com.sun.star.text.TextTable") then
   PortionEnum = thisMain.createEnumeration
   EnumeratePortions(PortionEnum)
  Else CellNames = thisMain.getCellNames
   For C = 0 to uBound(CellNames())
    oCell = thisMain.getCellByName(CellNames(C))
    ParaEnum = oCell.createEnumeration
    While ParaEnum.hasMoreElements
     thisPara = ParaEnum.nextElement
     PortionEnum = thisPara.createEnumeration
     EnumeratePortions(PortionEnum)
    Wend
   Next
 EndIf
Wend
End Sub

Sub EnumeratePortions(PortionEnum)
While PortionEnum.hasMoreElements
 thisPortion = PortionEnum.nextElement
 If thisPortion.TextPortionType <> "Text" then
  Print thisPortion.TextPortionType
 EndIf
Wend
End Sub


Last edited by JohnV on Wed Dec 20, 2006 6:27 am; edited 1 time in total
Back to top
View user's profile Send private message
Hagar Delest
Super User
Super User


Joined: 06 Feb 2006
Posts: 5164
Location: France

PostPosted: Wed Dec 20, 2006 1:42 am    Post subject: Reply with quote

Many thanks John, it works like a charm.
_________________
Now on the EN user community forum
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