You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2018/11/02 18:35:35 UTC
svn commit: r1845617 [4/5] - in /poi/branches/hemf: ./ jenkins/ maven/
sonar/ src/examples/src/org/apache/poi/hssf/usermodel/examples/
src/examples/src/org/apache/poi/ss/examples/
src/examples/src/org/apache/poi/xssf/usermodel/examples/ src/java/org/ap...
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java Fri Nov 2 18:35:34 2018
@@ -33,20 +33,20 @@ import org.openxmlformats.schemas.spread
* Test asserts the POI produces <cols> element that could be read and properly interpreted by the MS Excel.
* For specification of the "cols" element see the chapter 3.3.1.16 of the "Office Open XML Part 4 - Markup Language Reference.pdf".
* The specification can be downloaded at http://www.ecma-international.org/publications/files/ECMA-ST/Office%20Open%20XML%201st%20edition%20Part%204%20(PDF).zip.
- *
+ *
* <p><em>
* The test saves xlsx file on a disk if the system property is set:
* -Dpoi.test.xssf.output.dir=${workspace_loc}/poi/build/xssf-output
* </em>
- *
+ *
*/
public class TestXSSFColGrouping {
-
+
private static final POILogger logger = POILogFactory.getLogger(TestXSSFColGrouping.class);
-
+
/**
- * Tests that POI doesn't produce "col" elements without "width" attribute.
+ * Tests that POI doesn't produce "col" elements without "width" attribute.
* POI-52186
*/
@Test
@@ -56,25 +56,25 @@ public class TestXSSFColGrouping {
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
-
+
sheet.groupColumn((short) 4, (short) 7);
sheet.groupColumn((short) 9, (short) 12);
-
+
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGrouping");
sheet = wb2.getSheet("test");
-
+
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
for (CTCol col : cols.getColArray()) {
assertTrue("Col width attribute is unset: " + col, col.isSetWidth());
}
-
+
wb2.close();
wb1.close();
}
/**
- * Tests that POI doesn't produce "col" elements without "width" attribute.
+ * Tests that POI doesn't produce "col" elements without "width" attribute.
* POI-52186
*/
@Test
@@ -84,17 +84,17 @@ public class TestXSSFColGrouping {
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
-
+
sheet.groupColumn((short) 4, (short) 5);
-
+
sheet.setColumnGroupCollapsed(4, true);
-
+
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols);
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
sheet = wb2.getSheet("test");
-
+
for (int i = 4; i <= 5; i++) {
assertEquals("Unexpected width of column "+ i, 5000, sheet.getColumnWidth(i));
}
@@ -105,7 +105,7 @@ public class TestXSSFColGrouping {
wb2.close();
wb1.close();
}
-
+
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_2_WRAPS
*/
@@ -122,10 +122,10 @@ public class TestXSSFColGrouping {
col.setCustomWidth(true);
sheet.groupColumn((short) 2, (short) 3);
-
+
sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_WRAPS/cols:" + cols);
-
+
assertEquals(0, cols.getColArray(0).getOutlineLevel());
assertEquals(2, cols.getColArray(0).getMin()); // 1 based
assertEquals(2, cols.getColArray(0).getMax()); // 1 based
@@ -133,23 +133,23 @@ public class TestXSSFColGrouping {
assertEquals(1, cols.getColArray(1).getOutlineLevel());
assertEquals(3, cols.getColArray(1).getMin()); // 1 based
- assertEquals(4, cols.getColArray(1).getMax()); // 1 based
+ assertEquals(4, cols.getColArray(1).getMax()); // 1 based
assertEquals(true, cols.getColArray(1).getCustomWidth());
assertEquals(0, cols.getColArray(2).getOutlineLevel());
assertEquals(5, cols.getColArray(2).getMin()); // 1 based
assertEquals(5, cols.getColArray(2).getMax()); // 1 based
assertEquals(true, cols.getColArray(2).getCustomWidth());
-
+
assertEquals(3, cols.sizeOfColArray());
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_WRAPS");
sheet = wb2.getSheet("test");
-
+
for (int i = 1; i <= 4; i++) {
assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
}
-
+
wb2.close();
wb1.close();
}
@@ -170,10 +170,10 @@ public class TestXSSFColGrouping {
col.setCustomWidth(true);
sheet.groupColumn((short) 1, (short) 5);
-
+
cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_WRAPS/cols:" + cols);
-
+
assertEquals(1, cols.getColArray(0).getOutlineLevel());
assertEquals(2, cols.getColArray(0).getMin()); // 1 based
assertEquals(2, cols.getColArray(0).getMax()); // 1 based
@@ -181,23 +181,23 @@ public class TestXSSFColGrouping {
assertEquals(1, cols.getColArray(1).getOutlineLevel());
assertEquals(3, cols.getColArray(1).getMin()); // 1 based
- assertEquals(5, cols.getColArray(1).getMax()); // 1 based
+ assertEquals(5, cols.getColArray(1).getMax()); // 1 based
assertEquals(true, cols.getColArray(1).getCustomWidth());
assertEquals(1, cols.getColArray(2).getOutlineLevel());
assertEquals(6, cols.getColArray(2).getMin()); // 1 based
assertEquals(6, cols.getColArray(2).getMax()); // 1 based
assertEquals(false, cols.getColArray(2).getCustomWidth());
-
+
assertEquals(3, cols.sizeOfColArray());
-
+
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_WRAPS");
sheet = wb2.getSheet("test");
-
+
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
}
-
+
wb2.close();
wb1.close();
}
@@ -218,7 +218,7 @@ public class TestXSSFColGrouping {
col.setCustomWidth(true);
sheet.groupColumn((short) 3, (short) 5);
-
+
cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_MINOR/cols:" + cols);
@@ -229,24 +229,24 @@ public class TestXSSFColGrouping {
assertEquals(1, cols.getColArray(1).getOutlineLevel());
assertEquals(4, cols.getColArray(1).getMin()); // 1 based
- assertEquals(5, cols.getColArray(1).getMax()); // 1 based
+ assertEquals(5, cols.getColArray(1).getMax()); // 1 based
assertEquals(true, cols.getColArray(1).getCustomWidth());
assertEquals(1, cols.getColArray(2).getOutlineLevel());
assertEquals(6, cols.getColArray(2).getMin()); // 1 based
assertEquals(6, cols.getColArray(2).getMax()); // 1 based
assertEquals(false, cols.getColArray(2).getCustomWidth());
-
+
assertEquals(3, cols.sizeOfColArray());
-
+
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_MINOR");
sheet = wb2.getSheet("test");
-
+
for (int i = 2; i <= 4; i++) {
- assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
+ assertEquals("Unexpected width of column "+ i, 20 * 256L, sheet.getColumnWidth(i));
}
- assertEquals("Unexpected width of column "+ 5, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(5));
-
+ assertEquals("Unexpected width of column "+ 5, sheet.getDefaultColumnWidth() * 256L, sheet.getColumnWidth(5));
+
wb2.close();
wb1.close();
}
@@ -267,7 +267,7 @@ public class TestXSSFColGrouping {
col.setCustomWidth(true);
sheet.groupColumn((short) 1, (short) 3);
-
+
cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_MINOR/cols:" + cols);
@@ -278,24 +278,24 @@ public class TestXSSFColGrouping {
assertEquals(1, cols.getColArray(1).getOutlineLevel());
assertEquals(3, cols.getColArray(1).getMin()); // 1 based
- assertEquals(4, cols.getColArray(1).getMax()); // 1 based
+ assertEquals(4, cols.getColArray(1).getMax()); // 1 based
assertEquals(true, cols.getColArray(1).getCustomWidth());
assertEquals(0, cols.getColArray(2).getOutlineLevel());
assertEquals(5, cols.getColArray(2).getMin()); // 1 based
assertEquals(5, cols.getColArray(2).getMax()); // 1 based
assertEquals(true, cols.getColArray(2).getCustomWidth());
-
+
assertEquals(3, cols.sizeOfColArray());
-
+
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_MINOR");
sheet = wb2.getSheet("test");
-
+
for (int i = 2; i <= 4; i++) {
- assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
+ assertEquals("Unexpected width of column "+ i, 20 * 256L, sheet.getColumnWidth(i));
}
- assertEquals("Unexpected width of column "+ 1, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(1));
-
+ assertEquals("Unexpected width of column "+ 1, sheet.getDefaultColumnWidth() * 256L, sheet.getColumnWidth(1));
+
wb2.close();
wb1.close();
}
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java Fri Nov 2 18:35:34 2018
@@ -23,7 +23,6 @@ import java.math.BigDecimal;
import java.util.List;
import org.apache.poi.ss.formula.DataValidationEvaluator;
-import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.BaseTestDataValidation;
import org.apache.poi.ss.usermodel.Cell;
@@ -57,16 +56,16 @@ public class TestXSSFDataValidation exte
/**
* For each validation type, there are two cells with the same validation. This tests
* application of a single validation definition to multiple cells.
- *
+ *
* For list ( 3 validations for explicit and 3 for formula )
- * - one validation that allows blank.
+ * - one validation that allows blank.
* - one that does not allow blank.
* - one that does not show the drop down arrow.
* = 2
- *
+ *
* For number validations ( integer/decimal and text length ) with 8 different types of operators.
- * = 50
- *
+ * = 50
+ *
* = 52 ( Total )
*/
assertEquals(52,dataValidations.size());
@@ -140,7 +139,7 @@ public class TestXSSFDataValidation exte
cell_10.setCellValue(XSSFDataValidation.operatorTypeMappings.get(operatorType).toString());
Cell cell_11 = row1.createCell(1);
Cell cell_21 = row1.createCell(2);
- Cell cell_22 = i==0 && j < 2 ? row2.createCell(2) : null;
+ Cell cell_22 = i==0 && j < 2 ? (row2 == null ? null : row2.createCell(2)) : null;
Cell cell_13 = row1.createCell(3);
@@ -170,7 +169,9 @@ public class TestXSSFDataValidation exte
assertEquals(++lastKnownNumValidations, ((XSSFSheet) sheet).getDataValidations().size());
cellRangeAddressList = new CellRangeAddressList();
- cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_22.getRowIndex(), cell_22.getRowIndex(), cell_22.getColumnIndex(), cell_22.getColumnIndex()));
+ if (cell_22 != null) {
+ cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_22.getRowIndex(), cell_22.getRowIndex(), cell_22.getColumnIndex(), cell_22.getColumnIndex()));
+ }
validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList);
setOtherValidationParameters( validation);
sheet.addValidationData(validation);
@@ -178,7 +179,9 @@ public class TestXSSFDataValidation exte
} else if(i==0 && j==1 ){
cellRangeAddressList = new CellRangeAddressList();
cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_21.getRowIndex(), cell_21.getRowIndex(), cell_21.getColumnIndex(), cell_21.getColumnIndex()));
- cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_22.getRowIndex(), cell_22.getRowIndex(), cell_22.getColumnIndex(), cell_22.getColumnIndex()));
+ if (cell_22 != null) {
+ cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_22.getRowIndex(), cell_22.getRowIndex(), cell_22.getColumnIndex(), cell_22.getColumnIndex()));
+ }
validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList);
setOtherValidationParameters( validation);
sheet.addValidationData(validation);
@@ -262,16 +265,16 @@ public class TestXSSFDataValidation exte
XSSFSheet sheet = wb.createSheet();
List<XSSFDataValidation> lst = sheet.getDataValidations(); //<-- works
assertEquals(0, lst.size());
-
+
//create the cell that will have the validation applied
sheet.createRow(0).createCell(0);
-
+
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("SUM($A$1:$A$1) <= 3500");
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
DataValidation validation = dataValidationHelper.createValidation(constraint, addressList);
sheet.addValidationData(validation);
-
+
// this line caused XmlValueOutOfRangeException , see Bugzilla 3965
lst = sheet.getDataValidations();
assertEquals(1, lst.size());
@@ -282,10 +285,10 @@ public class TestXSSFDataValidation exte
public void testDefaultErrorStyle() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
-
+
final XSSFDataValidation validation = createValidation(sheet);
sheet.addValidationData(validation);
-
+
final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
assertEquals(DataValidation.ErrorStyle.STOP, dataValidations.get(0).getErrorStyle());
}
@@ -295,22 +298,22 @@ public class TestXSSFDataValidation exte
public void testSetErrorStyles() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
-
+
XSSFDataValidation validation = createValidation(sheet);
sheet.addValidationData(validation);
-
+
// extract generated validation from sheet
List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
validation = dataValidations.get(0);
-
+
// test INFO
validation.setErrorStyle(DataValidation.ErrorStyle.INFO);
assertEquals(DataValidation.ErrorStyle.INFO, dataValidations.get(0).getErrorStyle());
-
+
// test WARNING
validation.setErrorStyle(DataValidation.ErrorStyle.WARNING);
assertEquals(DataValidation.ErrorStyle.WARNING, dataValidations.get(0).getErrorStyle());
-
+
// test STOP
validation.setErrorStyle(DataValidation.ErrorStyle.STOP);
assertEquals(DataValidation.ErrorStyle.STOP, dataValidations.get(0).getErrorStyle());
@@ -321,10 +324,10 @@ public class TestXSSFDataValidation exte
public void testDefaultAllowBlank() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
-
+
final XSSFDataValidation validation = createValidation(sheet);
sheet.addValidationData(validation);
-
+
final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
assertEquals(true, dataValidations.get(0).getCtDdataValidation().getAllowBlank());
}
@@ -334,12 +337,12 @@ public class TestXSSFDataValidation exte
public void testSetAllowBlankToFalse() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
-
+
final XSSFDataValidation validation = createValidation(sheet);
validation.getCtDdataValidation().setAllowBlank(false);
-
+
sheet.addValidationData(validation);
-
+
final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
assertEquals(false, dataValidations.get(0).getCtDdataValidation().getAllowBlank());
}
@@ -349,12 +352,12 @@ public class TestXSSFDataValidation exte
public void testSetAllowBlankToTrue() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
-
+
final XSSFDataValidation validation = createValidation(sheet);
validation.getCtDdataValidation().setAllowBlank(true);
-
+
sheet.addValidationData(validation);
-
+
final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
assertEquals(true, dataValidations.get(0).getCtDdataValidation().getAllowBlank());
}
@@ -370,7 +373,7 @@ public class TestXSSFDataValidation exte
DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("true");
return (XSSFDataValidation) dataValidationHelper.createValidation(constraint, new CellRangeAddressList(0, 0, 0, 0));
}
-
+
@Test
public void testTableBasedValidationList() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("dataValidationTableRange.xlsx")) {
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java Fri Nov 2 18:35:34 2018
@@ -17,14 +17,24 @@
package org.apache.poi.xssf.usermodel;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -437,6 +447,10 @@ public final class TestXSSFFormulaEvalua
assertEquals("D 0,068", evaluator.evaluate(wb.getSheetAt(0).getRow(1).getCell(1)));
}
+ /**
+ * see bug 62275
+ * @throws IOException
+ */
@Test
public void testBug62275() throws IOException {
try (Workbook wb = new XSSFWorkbook()) {
@@ -451,4 +465,29 @@ public final class TestXSSFFormulaEvalua
eval.evaluate(cell);
}
}
+
+ /**
+ * see bug 62834, handle when a shared formula range doesn't contain only formula cells
+ * @throws IOException
+ */
+ @Test
+ public void testBug62834() throws IOException {
+ try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("62834.xlsx")) {
+ FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+
+ Cell a2 = wb.getSheetAt(0).getRow(1).getCell(0);
+ Cell value = evaluator.evaluateInCell(a2);
+ assertEquals("wrong value A2", "a value", value.getStringCellValue());
+
+// evaluator.clearAllCachedResultValues();
+
+ Cell a3 = wb.getSheetAt(0).getRow(2).getCell(0);
+ value = evaluator.evaluateInCell(a3);
+ assertEquals("wrong value A3", "a value", value.getStringCellValue());
+
+ Cell a5 = wb.getSheetAt(0).getRow(4).getCell(0);
+ value = evaluator.evaluateInCell(a5);
+ assertEquals("wrong value A5", "another value", value.getStringCellValue());
+ }
+ }
}
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Fri Nov 2 18:35:34 2018
@@ -36,8 +36,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.poi.ss.usermodel.AutoFilter;
@@ -158,7 +158,7 @@ public final class TestXSSFSheet extends
assertEquals("", ftr.getLeft());
assertEquals("", ftr.getCenter());
assertEquals("", ftr.getRight());
-
+
wb2.close();
}
@@ -200,7 +200,7 @@ public final class TestXSSFSheet extends
// Defaults are odd
assertEquals("odd footer left", sheet.getFooter().getLeft());
assertEquals("odd header center", sheet.getHeader().getCenter());
-
+
workbook.close();
}
@@ -265,7 +265,7 @@ public final class TestXSSFSheet extends
sheet.createSplitPane(4, 8, 12, 12, 1);
assertEquals(8.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit(), 0.0);
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
-
+
workbook.close();
}
@@ -374,7 +374,7 @@ public final class TestXSSFSheet extends
colArray = cols.getColArray();
assertEquals(4, colArray.length);
assertEquals(2, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol());
-
+
workbook.close();
}
@@ -411,7 +411,7 @@ public final class TestXSSFSheet extends
assertEquals(3, sheet.getPhysicalNumberOfRows());
assertEquals(1, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelRow());
-
+
workbook.close();
}
@@ -553,10 +553,10 @@ public final class TestXSSFSheet extends
checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
checkColumnGroup(cols.getColArray(4), 12, 12, false, false);
checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
-
+
wb2.close();
}
-
+
/**
* Verify that column groups were created correctly after Sheet.groupColumn
*
@@ -575,7 +575,7 @@ public final class TestXSSFSheet extends
assertEquals("isSetHidden", isSetHidden, col.isSetHidden());
assertEquals("isSetCollapsed", isSetCollapsed, col.isSetCollapsed()); //not necessarily set
}
-
+
/**
* Verify that column groups were created correctly after Sheet.groupColumn
*
@@ -708,7 +708,7 @@ public final class TestXSSFSheet extends
assertFalse(sheet1.getRow(16).getCTRow().isSetHidden());
assertFalse(sheet1.getRow(18).getCTRow().isSetCollapsed());
assertFalse(sheet1.getRow(18).getCTRow().isSetHidden());
-
+
wb2.close();
}
@@ -755,7 +755,7 @@ public final class TestXSSFSheet extends
assertEquals(4, col.getMax());
assertEquals(33.0, col.getWidth(), 0.0);
assertTrue(col.getCustomWidth());
-
+
workbook.close();
}
@@ -801,7 +801,7 @@ public final class TestXSSFSheet extends
//now the span is splitted into 5 individual columns
assertEquals(5, cols.sizeOfColArray());
for (int i = 0; i < 5; i++) {
- assertEquals(cw[i]*256, sheet.getColumnWidth(i));
+ assertEquals(cw[i]*256L, sheet.getColumnWidth(i));
assertEquals(cw[i], cols.getColArray(i).getWidth(), 0.0);
}
@@ -812,10 +812,10 @@ public final class TestXSSFSheet extends
cols = sheet.getCTWorksheet().getColsArray(0);
assertEquals(5, cols.sizeOfColArray());
for (int i = 0; i < 5; i++) {
- assertEquals(cw[i]*256, sheet.getColumnWidth(i));
+ assertEquals(cw[i]*256L, sheet.getColumnWidth(i));
assertEquals(cw[i], cols.getColArray(i).getWidth(), 0.0);
}
-
+
wb2.close();
}
@@ -889,7 +889,7 @@ public final class TestXSSFSheet extends
assertFalse(sheet.isColumnHidden(3));
assertFalse(sheet.isColumnHidden(4));
assertFalse(sheet.isColumnHidden(5));
-
+
wb2.close();
}
@@ -920,7 +920,7 @@ public final class TestXSSFSheet extends
//comment1 and comment2 are different objects
assertNotSame(comment1, comment2);
wb1.close();
-
+
//now test against a workbook containing cell comments
XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
sheet1 = wb2.getSheetAt(0);
@@ -928,7 +928,7 @@ public final class TestXSSFSheet extends
assertNotNull(comment1);
assertEquals("/xl/comments1.xml", comment1.getPackagePart().getPartName().getName());
assertSame(comment1, sheet1.getCommentsTable(true));
-
+
wb2.close();
}
@@ -1034,7 +1034,7 @@ public final class TestXSSFSheet extends
assertTrue(nm.getCTName().getHidden());
assertEquals("_xlnm._FilterDatabase", nm.getCTName().getName());
assertEquals("'new sheet'!$A$1:$D$100", nm.getCTName().getStringValue());
-
+
wb.close();
}
@@ -1057,7 +1057,7 @@ public final class TestXSSFSheet extends
sheet.protectSheet(null);
assertNull("protectSheet(null) should unset CTSheetProtection", sheet.getCTWorksheet().getSheetProtection());
-
+
wb.close();
}
@@ -1095,12 +1095,12 @@ public final class TestXSSFSheet extends
wb1.close();
assertTrue(wb2.getSheetAt(0).validateSheetPassword(password));
wb2.close();
-
+
XSSFWorkbook wb3 = openSampleWorkbook("workbookProtection-sheet_password-2013.xlsx");
assertTrue(wb3.getSheetAt(0).validateSheetPassword("pwd"));
wb3.close();
}
-
+
@Test
public void bug49966() throws IOException {
@@ -1161,7 +1161,7 @@ public final class TestXSSFSheet extends
XSSFSheet sheet = wb1.createSheet("Sheet 1");
assertFalse(sheet.getForceFormulaRecalculation());
-
+
// Set
sheet.setForceFormulaRecalculation(true);
assertTrue(sheet.getForceFormulaRecalculation());
@@ -1221,7 +1221,7 @@ public final class TestXSSFSheet extends
}
swb.close();
}
-
+
wb.close();
}
@@ -1246,7 +1246,7 @@ public final class TestXSSFSheet extends
}
swb.close();
}
-
+
wb.close();
}
@@ -1295,7 +1295,7 @@ public final class TestXSSFSheet extends
name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
assertNotNull(name);
assertEquals("Sheet0!$B:$C", name.getRefersToFormula());
-
+
wb.close();
}
@@ -1389,7 +1389,7 @@ public final class TestXSSFSheet extends
XSSFPivotTable pivotTable = sheet2.createPivotTable
(wb.getCreationHelper().createAreaReference("A1:B2"), new CellReference("H5"), sheet1);
assertEquals(0, pivotTable.getRowLabelColumns().size());
-
+
assertEquals(1, wb.getPivotTables().size());
assertEquals(0, sheet1.getPivotTables().size());
assertEquals(1, sheet2.getPivotTables().size());
@@ -1421,12 +1421,12 @@ public final class TestXSSFSheet extends
sheet2);
wb.close();
}
-
+
@Test(expected=POIXMLException.class)
public void testReadFails() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
-
+
// Throws exception because we cannot read here
try {
sheet.onDocumentRead();
@@ -1434,8 +1434,8 @@ public final class TestXSSFSheet extends
wb.close();
}
}
-
- /**
+
+ /**
* This would be better off as a testable example rather than a simple unit test
* since Sheet.createComment() was deprecated and removed.
* https://poi.apache.org/spreadsheet/quick-guide.html#CellComments
@@ -1450,7 +1450,7 @@ public final class TestXSSFSheet extends
assertNotNull(comment);
wb.close();
}
-
+
protected void testCopyOneRow(String copyRowsTestWorkbook) throws IOException {
final double FLOAT_PRECISION = 1e-9;
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(copyRowsTestWorkbook);
@@ -1496,24 +1496,24 @@ public final class TestXSSFSheet extends
cell = CellUtil.getCell(destRow, col++);
assertEquals("[String] G7 cell type", CellType.STRING, cell.getCellType());
assertEquals("[String] G7 cell value", "Hello", cell.getStringCellValue());
-
+
// Int
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Int] H7 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Int] H7 cell value", 15, (int) cell.getNumericCellValue());
-
+
// Float
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Float] I7 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Float] I7 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION);
-
+
// Cell Formula
cell = CellUtil.getCell(destRow, col++);
assertEquals("J7", new CellReference(cell).formatAsString());
assertEquals("[Cell Formula] J7 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J7 cell formula", "5+2", cell.getCellFormula());
//System.out.println("Cell formula evaluation currently unsupported");
-
+
// Cell Formula with Reference
// Formula row references should be adjusted by destRowNum-srcRowNum
cell = CellUtil.getCell(destRow, col++);
@@ -1522,21 +1522,21 @@ public final class TestXSSFSheet extends
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference] K7 cell formula",
"J7+H$2", cell.getCellFormula());
-
+
// Cell Formula with Reference spanning multiple rows
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell type",
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell formula",
"G7&\" \"&G8", cell.getCellFormula());
-
+
// Cell Formula with Reference spanning multiple rows
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Cell Formula with Area Reference] M7 cell type",
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Area Reference] M7 cell formula",
"SUM(H7:I8)", cell.getCellFormula());
-
+
// Array Formula
cell = CellUtil.getCell(destRow, col++);
//System.out.println("Array formulas currently unsupported");
@@ -1545,7 +1545,7 @@ public final class TestXSSFSheet extends
assertEquals("[Array Formula] N7 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Array Formula] N7 cell formula", "{SUM(H7:J7*{1,2,3})}", cell.getCellFormula());
*/
-
+
// Data Format
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Data Format] O7 cell type;", CellType.NUMERIC, cell.getCellType());
@@ -1553,14 +1553,14 @@ public final class TestXSSFSheet extends
//FIXME: currently fails
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
assertEquals("[Data Format] O7 data format", moneyFormat, cell.getCellStyle().getDataFormatString());
-
+
// Merged
cell = CellUtil.getCell(destRow, col);
assertEquals("[Merged] P7:Q7 cell value",
"Merged cells", cell.getStringCellValue());
assertTrue("[Merged] P7:Q7 merged region",
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P7:Q7")));
-
+
// Merged across multiple rows
// Microsoft Excel 2013 does not copy a merged region unless all rows of
// the source merged region are selected
@@ -1571,23 +1571,23 @@ public final class TestXSSFSheet extends
// which will not overwrite a cell in destination row if merged region extends beyond the copied row.
// The Excel way would require:
//assertEquals("[Merged across multiple rows] R7:S8 merged region", "Should NOT be overwritten", cell.getStringCellValue());
- //assertFalse("[Merged across multiple rows] R7:S8 merged region",
+ //assertFalse("[Merged across multiple rows] R7:S8 merged region",
// sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8")));
// As currently implemented, cell value is copied but merged region is not copied
assertEquals("[Merged across multiple rows] R7:S8 cell value",
"Merged cells across multiple rows", cell.getStringCellValue());
- assertFalse("[Merged across multiple rows] R7:S7 merged region (one row)",
+ assertFalse("[Merged across multiple rows] R7:S7 merged region (one row)",
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S7"))); //shouldn't do 1-row merge
- assertFalse("[Merged across multiple rows] R7:S8 merged region",
+ assertFalse("[Merged across multiple rows] R7:S8 merged region",
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8"))); //shouldn't do 2-row merge
-
+
// Make sure other rows are blank (off-by-one errors)
assertNull(sheet.getRow(5));
assertNull(sheet.getRow(7));
-
+
wb.close();
}
-
+
protected void testCopyMultipleRows(String copyRowsTestWorkbook) throws IOException {
final double FLOAT_PRECISION = 1e-9;
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(copyRowsTestWorkbook);
@@ -1595,8 +1595,7 @@ public final class TestXSSFSheet extends
final CellCopyPolicy defaultCopyPolicy = new CellCopyPolicy();
sheet.copyRows(0, 3, 8, defaultCopyPolicy);
- @SuppressWarnings("unused")
- final Row srcHeaderRow = sheet.getRow(0);
+ sheet.getRow(0);
final Row srcRow1 = sheet.getRow(1);
final Row srcRow2 = sheet.getRow(2);
final Row srcRow3 = sheet.getRow(3);
@@ -1606,102 +1605,102 @@ public final class TestXSSFSheet extends
final Row destRow3 = sheet.getRow(11);
int col = 0;
Cell cell;
-
+
// Header row should be copied
assertNotNull(destHeaderRow);
-
+
// Data rows
cell = CellUtil.getCell(destRow1, col);
assertEquals("Source row ->", cell.getStringCellValue());
-
+
// Style
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Style] B10 cell value", "Red", cell.getStringCellValue());
assertEquals("[Style] B10 cell style", CellUtil.getCell(srcRow1, 1).getCellStyle(), cell.getCellStyle());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Style] B11 cell value", "Blue", cell.getStringCellValue());
assertEquals("[Style] B11 cell style", CellUtil.getCell(srcRow2, 1).getCellStyle(), cell.getCellStyle());
-
+
// Blank
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Blank] C10 cell type", CellType.BLANK, cell.getCellType());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Blank] C11 cell type", CellType.BLANK, cell.getCellType());
-
+
// Error
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Error] D10 cell type", CellType.ERROR, cell.getCellType());
FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
assertEquals("[Error] D10 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Error] D11 cell type", CellType.ERROR, cell.getCellType());
error = FormulaError.forInt(cell.getErrorCellValue());
assertEquals("[Error] D11 cell value", FormulaError.NAME, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
-
+
// Date
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Date] E10 cell type", CellType.NUMERIC, cell.getCellType());
Date date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 1).getTime();
assertEquals("[Date] E10 cell value", date, cell.getDateCellValue());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Date] E11 cell type", CellType.NUMERIC, cell.getCellType());
date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 2).getTime();
assertEquals("[Date] E11 cell value", date, cell.getDateCellValue());
-
+
// Boolean
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Boolean] F10 cell type", CellType.BOOLEAN, cell.getCellType());
assertEquals("[Boolean] F10 cell value", true, cell.getBooleanCellValue());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Boolean] F11 cell type", CellType.BOOLEAN, cell.getCellType());
assertEquals("[Boolean] F11 cell value", false, cell.getBooleanCellValue());
-
+
// String
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[String] G10 cell type", CellType.STRING, cell.getCellType());
assertEquals("[String] G10 cell value", "Hello", cell.getStringCellValue());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[String] G11 cell type", CellType.STRING, cell.getCellType());
assertEquals("[String] G11 cell value", "World", cell.getStringCellValue());
-
+
// Int
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Int] H10 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Int] H10 cell value", 15, (int) cell.getNumericCellValue());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Int] H11 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Int] H11 cell value", 42, (int) cell.getNumericCellValue());
-
+
// Float
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Float] I10 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Float] I10 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION);
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Float] I11 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Float] I11 cell value", 5.5, cell.getNumericCellValue(), FLOAT_PRECISION);
-
+
// Cell Formula
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Cell Formula] J10 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J10 cell formula", "5+2", cell.getCellFormula());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Cell Formula] J11 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J11 cell formula", "6+18", cell.getCellFormula());
@@ -1714,11 +1713,11 @@ public final class TestXSSFSheet extends
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference] K10 cell formula",
"J10+H$2", cell.getCellFormula());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Cell Formula with Reference] K11 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference] K11 cell formula", "J11+H$2", cell.getCellFormula());
-
+
// Cell Formula with Reference spanning multiple rows
col++;
cell = CellUtil.getCell(destRow1, col);
@@ -1726,13 +1725,13 @@ public final class TestXSSFSheet extends
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell formula",
"G10&\" \"&G11", cell.getCellFormula());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell type",
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell formula",
"G11&\" \"&G12", cell.getCellFormula());
-
+
// Cell Formula with Area Reference
col++;
cell = CellUtil.getCell(destRow1, col);
@@ -1740,13 +1739,13 @@ public final class TestXSSFSheet extends
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Area Reference] M10 cell formula",
"SUM(H10:I11)", cell.getCellFormula());
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Cell Formula with Area Reference] M11 cell type",
CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Area Reference] M11 cell formula",
"SUM($H$3:I10)", cell.getCellFormula()); //Also acceptable: SUM($H10:I$3), but this AreaReference isn't in ascending order
-
+
// Array Formula
col++;
cell = CellUtil.getCell(destRow1, col);
@@ -1755,13 +1754,13 @@ public final class TestXSSFSheet extends
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
assertEquals("[Array Formula] N10 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Array Formula] N10 cell formula", "{SUM(H10:J10*{1,2,3})}", cell.getCellFormula());
-
+
cell = CellUtil.getCell(destRow2, col);
- // FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
+ // FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
assertEquals("[Array Formula] N11 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Array Formula] N11 cell formula", "{SUM(H11:J11*{1,2,3})}", cell.getCellFormula());
*/
-
+
// Data Format
col++;
cell = CellUtil.getCell(destRow2, col);
@@ -1769,7 +1768,7 @@ public final class TestXSSFSheet extends
assertEquals("[Data Format] O10 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION);
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
assertEquals("[Data Format] O10 cell data format", moneyFormat, cell.getCellStyle().getDataFormatString());
-
+
// Merged
col++;
cell = CellUtil.getCell(destRow1, col);
@@ -1777,42 +1776,42 @@ public final class TestXSSFSheet extends
"Merged cells", cell.getStringCellValue());
assertTrue("[Merged] P10:Q10 merged region",
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P10:Q10")));
-
+
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Merged] P11:Q11 cell value", "Merged cells", cell.getStringCellValue());
assertTrue("[Merged] P11:Q11 merged region",
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P11:Q11")));
-
+
// Should Q10/Q11 be checked?
-
+
// Merged across multiple rows
// Microsoft Excel 2013 does not copy a merged region unless all rows of
// the source merged region are selected
// POI's behavior should match this behavior
col += 2;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Merged across multiple rows] R10:S11 cell value",
+ assertEquals("[Merged across multiple rows] R10:S11 cell value",
"Merged cells across multiple rows", cell.getStringCellValue());
- assertTrue("[Merged across multiple rows] R10:S11 merged region",
+ assertTrue("[Merged across multiple rows] R10:S11 merged region",
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R10:S11")));
-
+
// Row 3 (zero-based) was empty, so Row 11 (zero-based) should be empty too.
if (srcRow3 == null) {
assertNull("Row 3 was empty, so Row 11 should be empty", destRow3);
}
-
+
// Make sure other rows are blank (off-by-one errors)
assertNull("Off-by-one lower edge case", sheet.getRow(7)); //one row above destHeaderRow
assertNull("Off-by-one upper edge case", sheet.getRow(12)); //one row below destRow3
-
+
wb.close();
}
-
+
@Test
public void testCopyOneRow() throws IOException {
testCopyOneRow("XSSFSheet.copyRows.xlsx");
}
-
+
@Test
public void testCopyMultipleRows() throws IOException {
testCopyMultipleRows("XSSFSheet.copyRows.xlsx");
@@ -1828,12 +1827,12 @@ public final class TestXSSFSheet extends
assertEquals(1, ignoredError.getSqref().size());
assertEquals("B2:D4", ignoredError.getSqref().get(0));
assertTrue(ignoredError.getNumberStoredAsText());
-
+
Map<IgnoredErrorType, Set<CellRangeAddress>> ignoredErrors = sheet.getIgnoredErrors();
assertEquals(1, ignoredErrors.size());
assertEquals(1, ignoredErrors.get(IgnoredErrorType.NUMBER_STORED_AS_TEXT).size());
assertEquals("B2:D4", ignoredErrors.get(IgnoredErrorType.NUMBER_STORED_AS_TEXT).iterator().next().formatAsString());
-
+
workbook.close();
}
@@ -1849,7 +1848,7 @@ public final class TestXSSFSheet extends
assertFalse(ignoredError.getNumberStoredAsText());
assertTrue(ignoredError.getFormula());
assertTrue(ignoredError.getEvalError());
-
+
Map<IgnoredErrorType, Set<CellRangeAddress>> ignoredErrors = sheet.getIgnoredErrors();
assertEquals(2, ignoredErrors.size());
assertEquals(1, ignoredErrors.get(IgnoredErrorType.FORMULA).size());
@@ -1867,19 +1866,19 @@ public final class TestXSSFSheet extends
// Two calls means two elements, no clever collapsing just yet.
sheet.addIgnoredErrors(region, IgnoredErrorType.EVALUATION_ERROR);
sheet.addIgnoredErrors(region, IgnoredErrorType.FORMULA);
-
+
CTIgnoredError ignoredError = sheet.getCTWorksheet().getIgnoredErrors().getIgnoredErrorArray(0);
assertEquals(1, ignoredError.getSqref().size());
assertEquals("B2:D4", ignoredError.getSqref().get(0));
assertFalse(ignoredError.getFormula());
assertTrue(ignoredError.getEvalError());
-
+
ignoredError = sheet.getCTWorksheet().getIgnoredErrors().getIgnoredErrorArray(1);
assertEquals(1, ignoredError.getSqref().size());
assertEquals("B2:D4", ignoredError.getSqref().get(0));
assertTrue(ignoredError.getFormula());
assertFalse(ignoredError.getEvalError());
-
+
Map<IgnoredErrorType, Set<CellRangeAddress>> ignoredErrors = sheet.getIgnoredErrors();
assertEquals(2, ignoredErrors.size());
assertEquals(1, ignoredErrors.get(IgnoredErrorType.FORMULA).size());
@@ -1888,7 +1887,7 @@ public final class TestXSSFSheet extends
assertEquals("B2:D4", ignoredErrors.get(IgnoredErrorType.EVALUATION_ERROR).iterator().next().formatAsString());
workbook.close();
}
-
+
@Test
public void setTabColor() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
@@ -1900,7 +1899,7 @@ public final class TestXSSFSheet extends
sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed());
}
}
-
+
@Test
public void getTabColor() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
@@ -1912,7 +1911,7 @@ public final class TestXSSFSheet extends
assertEquals(expected, sh.getTabColor());
}
}
-
+
// Test using an existing workbook saved by Excel
@Test
public void tabColor() throws IOException {
@@ -1930,7 +1929,7 @@ public final class TestXSSFSheet extends
assertEquals(expected, wb.getSheet("customOrange").getTabColor());
}
}
-
+
/**
* See bug #52425
*/
@@ -1947,7 +1946,7 @@ public final class TestXSSFSheet extends
// Adding Comment to cloned Sheet 3
addComments(helper, sheet3);
}
-
+
private void addComments(CreationHelper helper, Sheet sheet) {
Drawing<?> drawing = sheet.createDrawingPatriarch();
@@ -1974,7 +1973,7 @@ public final class TestXSSFSheet extends
}
}
-
+
// bug 59687: XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments
@Test
public void testRemoveRowWithCommentAndGapAbove() throws IOException {
@@ -1984,22 +1983,22 @@ public final class TestXSSFSheet extends
// comment exists
CellAddress commentCellAddress = new CellAddress("A4");
assertNotNull(sheet.getCellComment(commentCellAddress));
-
+
assertEquals("Wrong starting # of comments", 1, sheet.getCellComments().size());
-
+
sheet.removeRow(sheet.getRow(commentCellAddress.getRow()));
-
+
assertEquals("There should not be any comments left!", 0, sheet.getCellComments().size());
}
-
+
@Test
public void testGetHeaderFooterProperties() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sh = wb.createSheet();
-
+
XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
assertNotNull(hfProp);
-
+
wb.close();
}
}
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Fri Nov 2 18:35:34 2018
@@ -1044,8 +1044,10 @@ public final class TestXSSFWorkbook exte
//assertCloseDoesNotModifyFile(filename, wb);
// InputStream
- wb = new XSSFWorkbook(new FileInputStream(file));
- assertCloseDoesNotModifyFile(filename, wb);
+ try (FileInputStream is = new FileInputStream(file)) {
+ wb = new XSSFWorkbook(is);
+ assertCloseDoesNotModifyFile(filename, wb);
+ }
// OPCPackage
//wb = new XSSFWorkbook(OPCPackage.open(file));
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java Fri Nov 2 18:35:34 2018
@@ -65,7 +65,7 @@ public class TestXSSFChartTitle {
row = sheet.createRow((short) rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
cell = row.createCell((short) colIndex);
- cell.setCellValue(colIndex * (rowIndex + 1));
+ cell.setCellValue(colIndex * (rowIndex + 1L));
}
}
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java Fri Nov 2 18:35:34 2018
@@ -25,6 +25,9 @@ import static org.junit.Assert.assertTru
import java.io.IOException;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -192,14 +195,14 @@ public final class TestColumnHelper {
}
@Test
- public void testAddCleanColIntoColsExactOverlap() throws Exception {
+ public void testAddCleanColIntoColsExactOverlap() {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 1, 1, 1);
assertEquals(1, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, true);
}
@Test
- public void testAddCleanColIntoColsOverlapsOverhangingBothSides() throws Exception {
+ public void testAddCleanColIntoColsOverlapsOverhangingBothSides() {
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
@@ -208,7 +211,7 @@ public final class TestColumnHelper {
}
@Test
- public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
+ public void testAddCleanColIntoColsOverlapsCompletelyNested() {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
@@ -217,7 +220,7 @@ public final class TestColumnHelper {
}
@Test
- public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception {
+ public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() {
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
assertEquals(2, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
@@ -225,7 +228,7 @@ public final class TestColumnHelper {
}
@Test
- public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception {
+ public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
assertEquals(2, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 2, true, true);
@@ -233,7 +236,7 @@ public final class TestColumnHelper {
}
@Test
- public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception {
+ public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() {
CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
@@ -242,7 +245,7 @@ public final class TestColumnHelper {
}
@Test
- public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception {
+ public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
@@ -402,4 +405,36 @@ public final class TestColumnHelper {
}
return count;
}
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testColumnsCollapsed() {
+ Workbook wb = new XSSFWorkbook();
+ Sheet sheet = wb.createSheet("test");
+ Row row = sheet.createRow(0);
+ row.createCell(0);
+ row.createCell(1);
+ row.createCell(2);
+
+ sheet.setColumnWidth(0, 10);
+ sheet.setColumnWidth(1, 10);
+ sheet.setColumnWidth(2, 10);
+
+ sheet.groupColumn(0, 1);
+ sheet.setColumnGroupCollapsed(0, true);
+
+ CTCols ctCols = ((XSSFSheet) sheet).getCTWorksheet().getColsArray()[0];
+ assertEquals(3, ctCols.sizeOfColArray());
+ assertTrue(ctCols.getColArray(0).isSetCollapsed());
+ assertTrue(ctCols.getColArray(1).isSetCollapsed());
+ assertTrue(ctCols.getColArray(2).isSetCollapsed());
+
+ ColumnHelper helper = new ColumnHelper(CTWorksheet.Factory.newInstance());
+ helper.setColumnAttributes(ctCols.getColArray(1), ctCols.getColArray(2));
+
+ ctCols = ((XSSFSheet) sheet).getCTWorksheet().getColsArray()[0];
+ assertTrue(ctCols.getColArray(0).isSetCollapsed());
+ assertTrue(ctCols.getColArray(1).isSetCollapsed());
+ assertTrue(ctCols.getColArray(2).isSetCollapsed());
+ }
}
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/util/MemoryUsage.java Fri Nov 2 18:35:34 2018
@@ -17,18 +17,23 @@
package org.apache.poi.xssf.util;
-import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetData;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
-import java.util.List;
-import java.util.ArrayList;
+import junit.framework.TestCase;
/**
* Mixed utilities for testing memory usage in XSSF
@@ -37,7 +42,7 @@ import java.util.ArrayList;
*/
public class MemoryUsage extends TestCase {
private static final int NUM_COLUMNS = 255;
-
+
private static void printMemoryUsage(String msg) {
System.out.println(" Memory (" + msg + "): " + Runtime.getRuntime().totalMemory()/(1024*1024) + "MB");
}
@@ -62,8 +67,11 @@ public class MemoryUsage extends TestCas
Row row = sh.createRow(i);
for(int j=0; j < numCols; j++){
Cell cell = row.createCell(j);
- if(j % 2 == 0) cell.setCellValue(j);
- else cell.setCellValue(new CellReference(j, i).formatAsString());
+ if(j % 2 == 0) {
+ cell.setCellValue(j);
+ } else {
+ cell.setCellValue(new CellReference(j, i).formatAsString());
+ }
cnt++;
}
}
@@ -78,7 +86,7 @@ public class MemoryUsage extends TestCas
/**
* Generate a spreadsheet who's all cell values are numbers.
- * The data is generated until OutOfMemoryError.
+ * The data is generated until OutOfMemoryError.
* <p>
* as compared to {@link #mixedSpreadsheet(org.apache.poi.ss.usermodel.Workbook, int)},
* this method does not set string values and, hence, does not involve the Shared Strings Table.
@@ -161,7 +169,7 @@ public class MemoryUsage extends TestCas
rows.add(r);
}
} catch (OutOfMemoryError er) {
- System.out.println("Failed at row=" + i);
+ System.out.println("Failed at row=" + i + " from " + rows.size() + " kept.");
} catch (final Exception e) {
System.out.println("Unable to reach an OutOfMemoryError");
System.out.println(e.getClass().getName() + ": " + e.getMessage());
@@ -190,7 +198,7 @@ public class MemoryUsage extends TestCas
rows.add(r);
}
} catch (OutOfMemoryError er) {
- System.out.println("Failed at row=" + i);
+ System.out.println("Failed at row=" + i + " from " + rows.size() + " kept.");
} catch (final Exception e) {
System.out.println("Unable to reach an OutOfMemoryError");
System.out.println(e.getClass().getName() + ": " + e.getMessage());
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java Fri Nov 2 18:35:34 2018
@@ -29,6 +29,7 @@ import org.apache.poi.xwpf.XWPFTestDataS
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.POITestCase.assertEndsWith;
+import static org.apache.poi.POITestCase.assertNotContained;
import static org.apache.poi.POITestCase.assertStartsWith;
/**
@@ -441,4 +442,14 @@ public class TestXWPFWordExtractor exten
assertContains(txt, "Sequencing data");
extractor.close();
}
+
+ public void testGlossary() throws IOException {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60316.dotx");
+ XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
+ String txt = extractor.getText();
+ assertContains(txt, "Getting the perfect");
+ //this content appears only in the glossary document
+ //once we add processing for this, we can change this to contains
+ assertNotContained(txt, "table rows");
+ }
}
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java?rev=1845617&r1=1845616&r2=1845617&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java Fri Nov 2 18:35:34 2018
@@ -148,6 +148,19 @@ public final class TestXWPFSDT {
assertEquals("", sdts.get(0).getTitle());
}
+ @Test
+ public void test62859() throws IOException {
+ //this doesn't test the exact code path for this issue, but
+ //it does test for a related issue, and the fix fixes both.
+ //We should try to add the actual triggering document
+ //to our test suite.
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug62859.docx");
+ List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+ assertEquals(1, sdts.size());
+ assertEquals("", sdts.get(0).getTag());
+ assertEquals("", sdts.get(0).getTitle());
+ }
+
private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
List<XWPFAbstractSDT> sdts = new ArrayList<>();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org