You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by sreejithcools <sr...@beo.in> on 2012/12/12 05:04:13 UTC

Re: How to read the value of bookmarks? (docx)

I created a document template (docx) , and added bookmark .

my aim to replace the text along  the bookmark .

ex : 

[ bookmark]Hello World  

    I am able to replace but , the text Hello World is still there . 
    When i debug the code ,  i found out that , the bookmarkEnd tag is
before the text Hello World .
    How can i modify bookmark to change the bookmarkEnd tag to come after
the text Hello World .

Please help .

Sreejith 



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5711688.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to read the value of bookmarks? (docx)

Posted by Angelo zerr <an...@gmail.com>.
Hi,

If your goal is to manage mail merge (replace field in your docx with Java
value), you can see XDocReport <http://code.google.com/p/xdocreport/>.

Regards Angelo

2012/12/12 sreejithcools <sr...@beo.in>

> I created a document template (docx) , and added bookmark .
>
> my aim to replace the text along  the bookmark .
>
> ex :
>
> [ bookmark]Hello World
>
>     I am able to replace but , the text Hello World is still there .
>     When i debug the code ,  i found out that , the bookmarkEnd tag is
> before the text Hello World .
>     How can i modify bookmark to change the bookmarkEnd tag to come after
> the text Hello World .
>
> Please help .
>
> Sreejith
>
>
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5711688.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: How to read the value of bookmarks? (docx)

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
OK, so just to be clear, if you create a document using LibreOffice, insert a
bookmark and then try to insert some text at the bookmark's position, the
code fails completely? Are you saying that it does not insert the text at
all at the specified location? Or are you saying that because LibreOffice
does not allow you to bookmark text - Hello world in your example - then the
code will not replace the intended target? Sorry to be pedantic but the two
things are VERY different, one is a problem with the code posted on this
site - and something I could look at - the other a limitation of
LibreOffice.

Remember that bookmarks work as a pair of tags. There is an opening and a
closing bookmark tag and the replacement code works by matching them up and
replacing anything it finds in-between. If LibreOffice does not allow you to
bookmark text then the opening and closing tag pair will be - put simply -
empty. There is nothing to replace as far as the code is concerned and so
all it can do is insert some text into the document at the specified
location. To be clear, using your test LibreOffice document, is it doing
this?



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5711706.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to read the value of bookmarks? (docx)

Posted by sreejithcools <sr...@beo.in>.
Thanks for the reply , 

Actually i am working on Libreoffice till now for creating bookmark . It
does'nt allow you to add bookmark to a Selected text , it can add bookmark
only to a position some where in docx file .

Yesterday i tried in MS Word , giving bookmark , and then it worked smoothly
.
So the above code will work only if the bookmarks are created with MS Word . 





--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5711705.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to read the value of bookmarks? (docx)

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
I suspect that is happening because you did not bookmark the text but simply
inserted the bookmark into the document in front of the Hello world phrase. 

To see what I mean, try typing another phrase into the document say /to
replace/ for example. Now select that text as if you were going to change
the font or size but instead select the Insert->Bookmark menu options, type
a name for the bookmark into the box that appears and select Add. Now you
should have created a piece of text that is itself bookmarked and the code
ought to replace it for you. Off of the top of my head, I cannot remember
how to trun on the option but it is possible to tell Word to display the
start and end points of bookmarks in the text. You should see and opening [
symbol in the text to show where a bookmark begins and a matching ] to show
where it ends. Try to find out how to turn this on (I think it is somewhere
in the options settings) and I think it will show you that your original
example looks like this ][Hello world

Yours

Mark B

PS If you intend to use this code in a production environment, please test
it throughly.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5711689.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org