You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by vishman <vi...@db.com> on 2010/07/21 17:46:18 UTC

Word (docx) manipulation using POI

Hi Guys,
I am using Apache Poi to manipulate a word document with .docx extension. As
a part of manipulation I need to replace all the instances of a 
token(for eg. <<sometoken>>) with a simple field. Such a document can then
be updated based on the field name using POI.
So the sentence below,
“My vendor name is <<vendorName>> .”   would look like “My vendor name is
VIPVendor .” where VIPVendor is a simple filed with name vendorName

The document.xml will then be as below,

<w:p w:rsidR="001B7CEE" w:rsidRDefault="00883215">
<w:r><w:t xml:space="preserve">My vendor name is </w:t> </w:r>
<w:fldSimple w:instr="MERGEFIELD vendorName \* MERGEFORMAT">
<w:r><w:t> VIPVendor </w:t></w:r>
</w:fldSimple>
<w:r><w:t xml:space="preserve">.</w:t> </w:r>
</w:p>

As you can see that the paragraph now has 3 elements starting with Run,
SimpleField and a Run at the end.
If I have to insert a simple field like this, then I can use 
    CTSimpleField newField = currentPara.insertNewFldSimple(position);
But what should be the value of position? Does Paragraph assign a kind of
index position to all the elements within it?  
I can’t see any supporting methods on either XWPFParagraph or CTP. Does
anyone have come across such issue or has some better idea?

Any help is much appreciated.

Cheers,
Vishal.

-- 
View this message in context: http://old.nabble.com/Word-%28docx%29-manipulation-using-POI-tp29227511p29227511.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