You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/05/19 20:18:09 UTC
svn commit: r1744635 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java
Author: centic
Date: Thu May 19 20:18:08 2016
New Revision: 1744635
URL: http://svn.apache.org/viewvc?rev=1744635&view=rev
Log:
Apply patch for bug 59355: XSSFPivotTable::addColumnLabel sets the cell type of a cell outside of the source data area
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java?rev=1744635&r1=1744634&r2=1744635&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java Thu May 19 20:18:08 2016
@@ -334,9 +334,9 @@ public class XSSFPivotTable extends POIX
/**
* Add data field with data from the given column and specified function.
* @param function the function to be used on the data
- * @param index the index of the column to be used as column label.
- * The following functions exists:
- * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
+ * The following functions exists:
+ * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
+ * @param columnIndex the index of the column to be used as column label.
* @param valueFieldName the name of pivot table value field
*/
@Beta
@@ -355,7 +355,8 @@ public class XSSFPivotTable extends POIX
}
CTDataField dataField = dataFields.addNewDataField();
dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));
- Cell cell = getDataSheet().getRow(pivotArea.getFirstCell().getRow()).getCell(columnIndex);
+ Cell cell = getDataSheet().getRow(pivotArea.getFirstCell().getRow())
+ .getCell(pivotArea.getFirstCell().getCol() + columnIndex);
cell.setCellType(Cell.CELL_TYPE_STRING);
dataField.setName(valueFieldName);
dataField.setFld(columnIndex);
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java?rev=1744635&r1=1744634&r2=1744635&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java Thu May 19 20:18:08 2016
@@ -32,6 +32,8 @@ import org.openxmlformats.schemas.spread
public class TestXSSFPivotTable extends TestCase {
private XSSFPivotTable pivotTable;
+ private XSSFPivotTable offsetPivotTable;
+ private Cell offsetOuterCell;
@Override
public void setUp(){
@@ -71,6 +73,45 @@ public class TestXSSFPivotTable extends
AreaReference source = new AreaReference("A1:C2");
pivotTable = sheet.createPivotTable(source, new CellReference("H5"));
+
+ XSSFSheet offsetSheet = (XSSFSheet) wb.createSheet();
+
+ Row tableRow_1 = offsetSheet.createRow(1);
+ offsetOuterCell = tableRow_1.createCell(1);
+ offsetOuterCell.setCellValue(-1);
+ Cell tableCell_1_1 = tableRow_1.createCell(2);
+ tableCell_1_1.setCellValue("Row #");
+ Cell tableCell_1_2 = tableRow_1.createCell(3);
+ tableCell_1_2.setCellValue("Exponent");
+ Cell tableCell_1_3 = tableRow_1.createCell(4);
+ tableCell_1_3.setCellValue("10^Exponent");
+
+ Row tableRow_2 = offsetSheet.createRow(2);
+ Cell tableCell_2_1 = tableRow_2.createCell(2);
+ tableCell_2_1.setCellValue(0);
+ Cell tableCell_2_2 = tableRow_2.createCell(3);
+ tableCell_2_2.setCellValue(0);
+ Cell tableCell_2_3 = tableRow_2.createCell(4);
+ tableCell_2_3.setCellValue(1);
+
+ Row tableRow_3= offsetSheet.createRow(3);
+ Cell tableCell_3_1 = tableRow_3.createCell(2);
+ tableCell_3_1.setCellValue(1);
+ Cell tableCell_3_2 = tableRow_3.createCell(3);
+ tableCell_3_2.setCellValue(1);
+ Cell tableCell_3_3 = tableRow_3.createCell(4);
+ tableCell_3_3.setCellValue(10);
+
+ Row tableRow_4 = offsetSheet.createRow(4);
+ Cell tableCell_4_1 = tableRow_4.createCell(2);
+ tableCell_4_1.setCellValue(2);
+ Cell tableCell_4_2 = tableRow_4.createCell(3);
+ tableCell_4_2.setCellValue(2);
+ Cell tableCell_4_3 = tableRow_4.createCell(4);
+ tableCell_4_3.setCellValue(100);
+
+ AreaReference offsetSource = new AreaReference(new CellReference("C2"), new CellReference("E4"));
+ offsetPivotTable = offsetSheet.createPivotTable(offsetSource, new CellReference("C6"));
}
/**
@@ -268,4 +309,15 @@ public class TestXSSFPivotTable extends
}
fail();
}
+
+ /**
+ * Verify that the Pivot Table operates only within the referenced area, even when the
+ * first column of the referenced area is not index 0.
+ */
+ public void testAddDataColumnWithOffsetData() {
+ offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, offsetOuterCell.getCellType());
+
+ offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org