mirror of https://github.com/apache/poi.git
[bug-66039] show use of setCellFormulaValidation=false in a test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1900375 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5488f87674
commit
d280b74388
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue