This is very far from being a trivial task. I had a few thoughts that suggest a way to proceed but need to make it clear that I do not think there is an easy way to do this - there is no existing method that allows you to search for some text and replace it with a picture - thinking about it further, can you even do this with Word?
The first thing I might try is to iterate through the document, paragraph by paragraph and run byr run. Search for the search term in each run and, if you find it, use the addPicture method to insert a picture. It may be the case that the picture is inserted in approximately the correct place and, if so, all you need to do is some fine tweaking to the process. This is all based upon the assumption that the addPicture method will insert the image into the document at the point you have reached whilst iterating through it. Of course, I do not know if this is the case and suspect it may simply place the image at the end of the document but until you test it...... If this does not work, then you will need to start digging deeper. Bear in mind is that all of the paragraph's text will be organised into one or more runs. So, the first step is to search through the runs for your 'search term'. If the search term is in a run all on its own then the problem is a little more straightforward, if not, I think that you will need to strip it out so that it is in a run on its own. Next, you will need to substitute the xml markup for the drawing/picture into that run in place of the search term and, finally, upload the picture's data into the file. There are a few hooks and tools available to help you do this - for example, you can search for and replace text and I can see how this might possibly be used to replace the search term with the xml markup and it is possible to add a picture to a document - but it might require work. If you do get it working, please upload the patch to the project. Yours Mark B -- View this message in context: http://apache-poi.1045710.n5.nabble.com/how-to-replace-text-with-image-in-word07-tp4332616p4334274.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
