Atte André Jensen wrote:
Fernand Vanrie wrote:

Thanks for your reply!

Atte André Jensen wrote:
If someone could give a clue to what I',m doing wrong or help me a bit further, I'd greatly appreciate it.
No idee,

I think my problems might relate to the advice you gave me last week regarding "repeating part of document". I decided for a simple string insert instead of using dispatcher, since I thought I might get that working first (formatting of copied sections were lost, but I could live with that).

Now my problem is that each repeated part might contain one of these ###IMG_SOMETHING###-markers. So after first repeating the necessary parts (while modifying it slightly) I'm now trying to go over the document again an replacing the markers with images. And http://www.oooforum.org/forum/viewtopic.phtml?t=31682 leads me to believe that I cannot just copy the way I did, and then afterwards expect the document to be ok. I also tried saving it after the unfolding of repeats, and rereading if before replacing images, but that didn't seem to change anything.

So my office document can contain something like this:

###GROUP_LOOP_BEGIN###
Name of group: ###GROUP_NAME###
###IMG_GROUP?###
###GROUP_LOOP_END###

Provided I have two groups named GrA and GrB, this should end up as to:

Name of group: GrA
< inserted image IMG_GROUPGrA.png >
Name of group: GrB
< inserted image IMG_GROUPGrB.png >

Here's how I repeat the parts (ugly prototype code):

groupLoopBegin.setSearchString('###GROUP_LOOP_BEGIN###')
groupLoopEnd.setSearchString('###GROUP_LOOP_END###')
begin = doc.findFirst(groupLoopBegin)
groupNb = re.compile('(###IMG.*)GROUP[?](.*###)')
while begin:
    end = doc.findNext(begin.End,groupLoopEnd)
    if end:
        rangeCursor.gotoRange(begin,False)
        rangeCursor.gotoRange(end,True)

        loop = rangeCursor.String
        loop = loop.replace('###GROUP_LOOP_BEGIN###','')
        loop = loop.replace('###GROUP_LOOP_END###','')
        for j in range(len(groupNames)):
            i = len(groupNames)-j-1
thisLoop = groupNb.sub(r"\g<1>"+'GROUP'+str(i+1)+"\g<2>",loop)
            thisLoop = thisLoop.replace('###GROUP_NAME###',groupNames[i])
            if j == 0:
                text.insertString(rangeCursor, thisLoop, True)
            else:
                text.insertString(rangeCursor, thisLoop, False)

    begin = doc.findNext(end.End,groupLoopBegin)


After running this my example document part looks like this (works):

Name of group: GrA
###IMG_GROUPGrA###
Name of group: GrB
###IMG_GROUPGrB###

So this is when replacing these ###IMG...-markes that the image is only inserted one time, and actually even at a wrong place, namely before the first "Name of group...".
you must check the "placement " of your viewcursor and change the Graphicpropertiess like anchoring etc;;;to end up with a correct placement who largely depents on this properties

I'm wondering:

1) Could this text.insertString be the reason my images are not inserted correctly?
i can see why

2) I can't figure out how to do the copyint with dispatcher. Which would be the steps required for a) copying a cursor range to a dispatcher, modifying this content and inserting it a number of times instead of the cursor?
first "select the textportion  and then uses this code:

yourdocument = oDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dispatcher.executeDispatch(yourdocument, ".uno:Copy", "", 0, Array()) >> copies only yhe "selected portion"

dispatcher.executeDispatch(yourdocument, ".uno:Paste", "", 0, Array()) >> paste at the viewcursor

3) Since the save to odt + reload didn't work is there any other trick I could try to getting the document in a state where a regular image insert could work?
try my  code i uses when starting from a template

oTemplate.storetoURL( ConvertToURL(sfile), Array( MakePropertyValue("FilterName", "writer8" )) DocumentReOpen(ConvertToURL(sfile) ' verwijst naar SUB DocumentReOpen

Sub DocumentReOpen(sFileURL As String)
  Dim mFileProperties(0) As New com.sun.star.beans.PropertyValue

  mFileProperties(0).Name="MacroExecutionMode"
  mFileProperties(0).Value=4
oDocument = StarDesktop.LoadComponentFromURL(ConvertToURL(sfile), "_blank", 0, mFileProperties())
  oViewCursor = oDocument.Text.createTextCursor
   oTemplate.dispose

End Sub

Obviously I'm confused about quite a few things working with this, hope my explanations make sense to some extend :-)

after looking at your code do not miss the "next" and is that not the reason why you endup with 1 placed image _or try to save your document (oducument.store) after every insertion(i think i had the same problem in the paste)
_

but why not using Document.GraphicObjects.getElementNames() and working directly with the images

Because the images are not in the document, but I have some text markers that should be replaced on images from disc. Or am I misunderstanding you?
Nono I has misunderstood you :-)

Hop it help a bit




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

Reply via email to