Author: fanningpj
Date: Fri Apr 29 10:52:34 2022
New Revision: 1900375
URL: http://svn.apache.org/viewvc?rev=1900375&view=rev
Log:
[bug-66039] show use of setCellFormulaValidation=false in a test
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/TestStructuredReferences.java
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/TestStructuredReferences.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/TestStructuredReferences.java?rev=1900375&r1=1900374&r2=1900375&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/TestStructuredReferences.java
(original)
+++
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/TestStructuredReferences.java
Fri Apr 29 10:52:34 2022
@@ -30,6 +30,7 @@ import org.apache.poi.ss.usermodel.Table
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFTable;
@@ -105,6 +106,37 @@ class TestStructuredReferences {
}
}
+ @Test
+ void testCellFormulaValidationFalse() throws Exception {
+ //relates to https://bz.apache.org/bugzilla/show_bug.cgi?id=66039
+ try (XSSFWorkbook workbook = new XSSFWorkbook()) {
+ workbook.setCellFormulaValidation(false);
+ XSSFSheet sheet = workbook.createSheet();
+
+ //set sheet content
+ sheet.createRow(0).createCell(0).setCellValue("Field1");
+ sheet.getRow(0).createCell(1).setCellValue("Field2");
+ sheet.createRow(1).createCell(0).setCellValue(123);
+ sheet.getRow(1).createCell(1);
+
+ //create the table
+ String tableName = "Table1";
+ CellReference topLeft = new
CellReference(sheet.getRow(0).getCell(0));
+ CellReference bottomRight = new
CellReference(sheet.getRow(1).getCell(1));
+ AreaReference tableArea =
workbook.getCreationHelper().createAreaReference(topLeft, bottomRight);
+ XSSFTable dataTable = sheet.createTable(tableArea);
+ dataTable.setName(tableName);
+ dataTable.setDisplayName(tableName);
+
+ //set the formula in sheet - when setCellFormulaValidation=true
(the default), the code tries to
+ //tidy up this formula (but incorrectly, in this case) - gets
adjusted to Sheet0!A2:A2
+ XSSFCell formulaCell = sheet.getRow(1).getCell(1);
+ formulaCell.setCellFormula(tableName + "[[#This Row],[Field1]]");
+
+ assertEquals("Table1[[#This Row],[Field1]]",
formulaCell.getCellFormula());
+ }
+ }
+
private static void confirm(FormulaEvaluator fe, Cell cell, double
expectedResult) {
fe.clearAllCachedResultValues();
CellValue cv = fe.evaluate(cell);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]