Bug 70299 - Replacing a string by images only works for the first occurrence
Summary: Replacing a string by images only works for the first occurrence
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected) release
Hardware: x86-64 (AMD64) Mac OS X (All)
: medium normal
Assignee: Not Assigned
Depends on:
Reported: 2013-10-08 23:09 UTC by bernd.dongus
Modified: 2013-11-23 23:23 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description bernd.dongus 2013-10-08 23:09:23 UTC

I try to replace every occurrence of a certain string by an image. It loops, but writer only replaces the first occurence and I don't see why. Here ist the code:

I am using LO 4.1
The code:

Sub InsertLogo()
  Dim oGraph
  Dim oDescriptor  'The search descriptor
  Dim oFound       'The found range
  Dim oFoundAll    'The found range
  Dim n%           'General index variable
  Dim oCursor

  oGraph = ThisComponent.createInstance("com.sun.star.text.GraphicObject")
  With oGraph
    .GraphicURL = "file://localhost/anydirectory/logo.png"
    .AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
    .Width = 910
    .Height = 420
    .VertOrient = 4 'CHAR_TOP
  End With
  oDescriptor = ThisComponent.createSearchDescriptor()
  oDescriptor.SearchString = "{logo}"
  oFoundAll = ThisComponent.findAll(oDescriptor)
  For n% = 0 to oFoundAll.getCount()-1
	oFound = oFoundAll.getByIndex(n%)
	oCursor = oFound.getStart()
	oFound.getText().insertTextContent( oCursor, oGraph, False )

End Sub
Comment 1 Cor Nouws 2013-10-09 07:50:50 UTC
Hi Bern,

Working with graphics is a bit not straight forward (for me). 
I would try to make new instances (oGraph_n) for each replace. No idea if that works.
But it's not a support forum here, is it ;)
Could you find another place for help?

Comment 2 bernd.dongus 2013-10-09 22:16:24 UTC
Dear Cor.

Thanks for having a look at it.

I looked for help in several forums but I found/got no answer. I'll try as you advised.

Just being curious: Why isn't that a straight forward approach. I thought it is. :)

Comment 3 Jean-Baptiste Faure 2013-11-23 23:23:06 UTC
This bug tracker is not an helpdesk. Please ask for help on users mailing-list (users@global.libreoffice.org) or on http://ask.libreoffice.org

Closing as invalid.

Bes regards. JBF