we docx4j to replace find certain keyword in word document and replace it with other values.
however we find that when the values we replace contain new line or carriage return character
(ascii 10 and ascii 13). when we set with new value, it will automatically replace with white space (ascii 32).
e.g
newValue = 10/10/2010
11/10/2010
but in the word document after replace it will become "10/10/2010 11/10/2010"
we have debug, the newValue is contain the new line character before we set value.
any one having same cases before ?
below is our code :
- Code: Select all
if (((JAXBElement)child).getDeclaredType().getName().equals("org.docx4j.wml.Text"))
{
Text t = (Text)((JAXBElement)child).getValue();
for (int paramIndex=0; paramIndex<paramSize; paramIndex++)
{
tradeConfirmDetail = (TradeConfirmDetail) paramList.get(paramIndex);
textToReplace = "<" + tradeConfirmDetail.getConfirmColumnName() + ">";
if ((startPos = t.getValue().indexOf(textToReplace)) != -1)
{
newValue = t.getValue().substring(0, startPos) +
tradeConfirmDetail.getConfirmColumnValue() +
t.getValue().substring(startPos + textToReplace.length(), t.getValue().length());
t.setValue(newValue);
break;
}
}
}
Thanks & Regards
Yan