Hello,

hopefully, I'm correct here. I wasn't quite sure where to ask.

This is what I want to achieve: Every time, a specific document is printed, 
a makro shall generate a tracking code and insert that code into the 
document at a designated place.

I found a solution for normal text documents but not for documents that 
contain labels.


Here's what I found out so far:

After a lot of digging in api.openoffice.org, I came up with the following 
approach:

I put a table with only a single cell where I want the code to be placed. 
This table gets the name "Code". Then, I attach the following makro to the 
Print-Event:

<----- snip ----->
Sub Main
  Dim oTextDocument as object
  Dim oText as object
        
  Dim sCurrentCode as string
        
  ' For testing: set a constant code
  sCurrentCode = "XXXX-XXXX-XXXX"
 
  oTextDocument = ThisComponent 
  oTextEnum = oText.getText() 

  oTextElementEnum = oTextEnum.createEnumeration
  while oTextElementEnum.hasMoreElements()
    oTextElement = oTextElementEnum.nextElement
    if oTextElement.supportsService("com.sun.star.text.TextTable") then
      if oTextElement.Name="Code" then
        oCell = oTextElement.GetCellByPosition(0,0)
        oCell.setString(sCurrentCode)
      end if
    end if
  wend
End Sub
<----- snap ----->


This works fine. So far, so good.

Now, I want to do the same with a document that contains labels. You know, 
the things you get when using File -> New -> Labels. Format of the labels 
is 105x48 mm, allowing 2x6 labels on one ISO A4 page.

Alas, if I run the makro from above on this document, nothing happens. A 
little MsgBox tells me that the if-Clause is never reached.

I modified the makro to count how many elements are enumerated in the 
while-Loop and got the value 6. Since there are exactly 6 rows, I thought: 
Well, maybe the row are containers themselves, so lets enumerate through 
them as well.

After doing so, I still don't hit the table, but now run through a total of 
12 elements. I thought: Well, maybe each row consists of two containers 
(the columns with the label content). Like so:

  Document
   |
   +--- Rows (6)
         |
         +--- Columns (2)
               |
               + single Labels
                  |
                  +--- normal Content

Lets enumerate again. However, this doesn't work as well. I never hit any 
table. I even implemented a depth search:

<----- snip ----->

Sub DepthSearch(oElem as object)
  oEnum = oElem.getText.createEnumeration
  while oEnum.hasMoreElements()
    oSubElem = oEnum.nextElement
    if oSubElem.supportsService("com.sun.star.text.TextTable") then
      MsgBox "Hey, finally found a table!"
      exit sub
    EndIf
    
    if oSubElem.supportsService("com.sun.star.text.TextContent") then
      DepthSearch(oSubElem)
    EndIf
  wend
End Sub


Sub Main
  [ ...same code as above... ]

  while oTextElementEnum.hasMoreElements()
    oTextElement = oTextElementEnum.nextElement
    oInnerEnum = oTextElement.createEnumeration

    ' The lines with labels
    while oInnerEnum.hasMoreElements()
      oTextElement = oInnerEnum.nextElement
      DepthSearch(oTextElement)
    wend
  wend
End Sub
<----- snap ----->

This makro runs until a stack overflow stops it. Appearently, I somehow 
end up enumerating the same elements again and again, causing an infinite 
loop.

So my questions are:

1. How do I access the table within a label?
2. Is my approach using tables for this code correct? Maybe there
   is a better way...
3. Where can I find further information about labels and how they
   are using within makros? On api.openoffice.org, I only found
   some very basic stuff that doesn't help me.

TIA,
  Malte

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to