<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45269 - improve replaceText on HWPF ranges</action>
<action dev="POI-DEVELOPERS" type="fix">47815 - correct documentation on what happens when you request a String from a non-string Formula cell</action>
<action dev="POI-DEVELOPERS" type="fix">49386 - avoid NPE when extracting OOXML file properties which are dates</action>
<action dev="POI-DEVELOPERS" type="fix">49377 - only call DecimalFormat.setRoundingMode on Java 1.6 - it's needed to match excel's rendering of numbers</action>
subRange.insertBefore(pValue);
- if (subRange.getEndOffset() != previousEndOffset)
- _end += (subRange.getEndOffset() - previousEndOffset);
+ if (subRange.getEndOffset() != previousEndOffset) {
+ adjustForInsert(subRange.getEndOffset() - previousEndOffset);
+ }
// re-create the sub-range so we can delete it
subRange = new Range((absPlaceHolderIndex + pValue.length()), (absPlaceHolderIndex
HWPFDocument doc2 = writeOutAndRead(doc);
assertEquals("Nick Burch", doc2.getSummaryInformation().getAuthor());
}
+
+ /**
+ * Test for reading paragraphs from Range after replacing some
+ * text in this Range.
+ * Bug #45269
+ */
+ public void testReadParagraphsAfterReplaceText()throws Exception{
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug45269.doc");
+ Range range = doc.getRange();
+
+ String toFind = "campo1";
+ String longer = " foi porraaaaa ";
+ String shorter = " foi ";
+
+ //check replace with longer text
+ for (int x = 0; x < range.numParagraphs(); x++) {
+ Paragraph para = range.getParagraph(x);
+ int offset = para.text().indexOf(toFind);
+ if (offset >= 0) {
+ para.replaceText(toFind, longer, offset);
+ assertEquals(offset, para.text().indexOf(longer));
+ }
+ }
+
+ doc = HWPFTestDataSamples.openSampleFile("Bug45269.doc");
+ range = doc.getRange();
+
+ //check replace with shorter text
+ for (int x = 0; x < range.numParagraphs(); x++) {
+ Paragraph para = range.getParagraph(x);
+ int offset = para.text().indexOf(toFind);
+ if (offset >= 0) {
+ para.replaceText(toFind, shorter, offset);
+ assertEquals(offset, para.text().indexOf(shorter));
+ }
+ }
+ }
}
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ // Has one section
Range range = daDoc.getRange();
assertEquals(1, range.numSections());
+ // The first section has 5 paragraphs
Section section = range.getSection(0);
assertEquals(5, section.numParagraphs());
+
+ // Change some text
Paragraph para = section.getParagraph(2);
String text = para.text();
para.replaceText(searchText, replacementText, offset);
+ // Ensure we still have one section, 5 paragraphs
assertEquals(1, range.numSections());
section = range.getSection(0);
- assertEquals(4, section.numParagraphs());
+ assertEquals(5, section.numParagraphs());
para = section.getParagraph(2);
+ // Ensure the text is what we should now have
text = para.text();
assertEquals(expectedText2, text);
}