From 481a325c4583568ab9fc0190748431b9ebac7ec0 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 27 May 2011 14:48:22 +0000 Subject: [PATCH] Fix bug #47147 - XWPF table cells adding extra paragraph - test from Stefan Stern git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1128331 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/xwpf/usermodel/XWPFTable.java | 1 - .../poi/xwpf/usermodel/TestXWPFTable.java | 28 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 391721404..5f4b8f3fc 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 47147 - Correct extra paragraphs from XWPF Table Cells 51188 - Support for getting and setting XPWF zoom settings 51134 - Support for adding Numbering and Styles to a XWPF document that doesn't already have them 51273 - Formula Value Cache fix for repeated evaluations diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java index ec981cad3..d310b288a 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java @@ -51,7 +51,6 @@ public class XWPFTable implements IBodyElement{ this(table, part); for (int i = 0; i < row; i++) { XWPFTableRow tabRow = (getRow(i) == null) ? createRow() : getRow(i); - tableRows.add(tabRow); for (int k = 0; k < col; k++) { XWPFTableCell tabCell = (tabRow.getCell(k) == null) ? tabRow .createCell() : null; diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java index 6d9a0e93b..a8eaf1966 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java @@ -17,9 +17,11 @@ package org.apache.poi.xwpf.usermodel; import java.math.BigInteger; +import java.util.List; import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; @@ -130,4 +132,30 @@ public class TestXWPFTable extends TestCase { assertEquals(20, row.getHeight()); } + public void testCreateTable() throws Exception { + // open an empty document + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + + // create a table with 5 rows and 7 coloumns + int noRows = 5; + int noCols = 7; + XWPFTable table = doc.createTable(noRows,noCols); + + // assert the table is empty + List rows = table.getRows(); + assertEquals("Table has less rows than requested.", noRows, rows.size()); + for (XWPFTableRow xwpfRow : rows) + { + assertNotNull(xwpfRow); + for (int i = 0 ; i < 7 ; i++) + { + XWPFTableCell xwpfCell = xwpfRow.getCell(i); + assertNotNull(xwpfCell); + assertEquals("Empty cells should not have one paragraph.",1,xwpfCell.getParagraphs().size()); + xwpfCell = xwpfRow.getCell(i); + assertEquals("Calling 'getCell' must not modify cells content.",1,xwpfCell.getParagraphs().size()); + } + } + doc.getPackage().revert(); + } } \ No newline at end of file