From: Nick Burch Date: Fri, 25 Jan 2008 11:52:39 +0000 (+0000) Subject: Correctly handle the last paragraph via a fix to TableCell - patch from bug #44292 X-Git-Tag: REL_3_0_3_BETA1~173 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3fcfae722ba83c19ca1465c15b5c394b0959b5ce;p=poi.git Correctly handle the last paragraph via a fix to TableCell - patch from bug #44292 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@615190 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 51aeb22461..f11d64ad26 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 44292 - Correctly process the last paragraph in a word file 44254 - Avoid some unread byte warnings, and properly understand DVALRecord Add another formula evaluation method, evaluateFormulaCell(cell), which will re-calculate the value for a formula, without affecting the formula itself. 41726 - Fix how we handle signed cell offsets in relative areas and references diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index feabdf76b4..73375a336e 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 44292 - Correctly process the last paragraph in a word file 44254 - Avoid some unread byte warnings, and properly understand DVALRecord Add another formula evaluation method, evaluateFormulaCell(cell), which will re-calculate the value for a formula, without affecting the formula itself. 41726 - Fix how we handle signed cell offsets in relative areas and references diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java index ff9cf2b9c8..a88e32360e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java @@ -58,7 +58,7 @@ public class TableRow p = getParagraph(end); s = p.text(); } - _cells[cellIndex] = new TableCell(start, end, this, levelNum, + _cells[cellIndex] = new TableCell(start, end+1, this, levelNum, _tprops.getRgtc()[cellIndex], _tprops.getRgdxaCenter()[cellIndex], _tprops.getRgdxaCenter()[cellIndex+1]-_tprops.getRgdxaCenter()[cellIndex]); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug44292.doc b/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug44292.doc new file mode 100644 index 0000000000..fd7ca6cc3e Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug44292.doc differ diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java index 8e7f47ed96..e82c4d1304 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java @@ -74,4 +74,34 @@ public class TestProblems extends TestCase { } } } + + /** + * Test for TableCell not skipping the last paragraph + */ + public void testTableCellLastParagraph() throws Exception { + HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/Bug44292.doc")); + Range r = doc.getRange(); + + //get the table + Paragraph p = r.getParagraph(0); + Table t = r.getTable(p); + + //get the only row + TableRow row = t.getRow(0); + + //get the first cell + TableCell cell = row.getCell(0); + // First cell should have one paragraph + assertEquals(1, cell.numParagraphs()); + + //get the second + cell = row.getCell(1); + // Second cell should be detected as having two paragraphs + assertEquals(2, cell.numParagraphs()); + + //get the last cell + cell = row.getCell(2); + // Last cell should have one paragraph + assertEquals(1, cell.numParagraphs()); + } }