Atte André Jensen wrote:
Hi

I'm trying to replace every occurrence of ###IMGsome_img.png### with the appropriate image (in the above example some_img.png). The following snippet (python) is what I have, although with some successful checking removed. However it only replaces the first of multiple, successive occurrences of the same image. 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, but why not using Document.GraphicObjects.getElementNames() and working directly with the images

text = doc.getText()
descriptor = doc.createSearchDescriptor()
descriptor.setSearchString('###IMG.*###')
descriptor.SearchRegularExpression = True
foundCursors = doc.findAll(descriptor)
nbFound = foundCursors.getCount()
if nbFound > 0:
    for i in range(0,nbFound):
        oneCursor = foundCursors.getByIndex(i)
thisImagePath = os.path.abspath(imgPath) + '/' + oneCursor.String.replace('###','') + '.png'
        imageUrl = absolutize( cwd, systemPathToFileUrl(thisImagePath) )
        image = doc.createInstance("com.sun.star.text.GraphicObject")
        image.GraphicURL = imageUrl
        text.insertTextContent(oneCursor, image, True)



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

Reply via email to