You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/07/04 19:09:10 UTC
svn commit: r1751373 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xssf/usermodel/XSSFTable.java
testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Author: onealj
Date: Mon Jul 4 19:09:10 2016
New Revision: 1751373
URL: http://svn.apache.org/viewvc?rev=1751373&view=rev
Log:
bug 59796: XSSFTable#getRowCount off-by-one error
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java?rev=1751373&r1=1751372&r2=1751373&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java Mon Jul 4 19:09:10 2016
@@ -324,8 +324,9 @@ public class XSSFTable extends POIXMLDoc
/**
- * @return the total number of rows in the selection. (Note: in this version autofiltering is ignored)
- *
+ * @return the total number of rows in the selection. (Note: in this version autofiltering is ignored)
+ * Returns <code>0</code> if the start or end cell references are not set.
+ *
* Does not track updates to underlying changes to CTTable
* To synchronize with changes to the underlying CTTable,
* call {@link #updateReferences()}.
@@ -334,10 +335,9 @@ public class XSSFTable extends POIXMLDoc
CellReference from = getStartCellReference();
CellReference to = getEndCellReference();
- int rowCount = -1;
+ int rowCount = 0;
if (from!=null && to!=null) {
- // FIXME: shouldn't this be to-from+1?
- rowCount = to.getRow()-from.getRow();
+ rowCount = to.getRow() - from.getRow() + 1;
}
return rowCount;
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1751373&r1=1751372&r2=1751373&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Mon Jul 4 19:09:10 2016
@@ -267,4 +267,24 @@ public final class TestXSSFTable {
assertEquals(new CellReference("M3"), table.getEndCellReference());
}
+
+ @Test
+ public void getRowCount() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sh = wb.createSheet();
+ XSSFTable table = sh.createTable();
+ CTTable ctTable = table.getCTTable();
+
+ assertEquals(0, table.getRowCount());
+
+ ctTable.setRef("B2:B2");
+ // update cell references to clear the cache
+ table.updateReferences();
+ assertEquals(1, table.getRowCount());
+
+ ctTable.setRef("B2:B12");
+ // update cell references to clear the cache
+ table.updateReferences();
+ assertEquals(11, table.getRowCount());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org