use of org.apache.poi.ss.usermodel.DataValidationConstraint in project poi by apache.
the class TestXSSFDataValidation method test53965.
@Test
public void test53965() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
try {
XSSFSheet sheet = wb.createSheet();
//<-- works
List<XSSFDataValidation> lst = sheet.getDataValidations();
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());
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.DataValidationConstraint in project poi by apache.
the class TestXSSFDataValidationConstraint method listLiteralsQuotesAreStripped_arrayConstructor.
@Test
public void listLiteralsQuotesAreStripped_arrayConstructor() {
// literal list, using array constructor
String literal = "\"one, two, three\"";
String[] expected = new String[] { "one", "two", "three" };
DataValidationConstraint constraint = new XSSFDataValidationConstraint(expected);
assertArrayEquals(expected, constraint.getExplicitListValues());
// Excel and DataValidationConstraint parser ignore (strip) whitespace; quotes should still be intact
assertEquals(literal.replace(" ", ""), constraint.getFormula1());
}
use of org.apache.poi.ss.usermodel.DataValidationConstraint in project poi by apache.
the class TestXSSFDataValidationConstraint method namedRangeReference.
@Test
public void namedRangeReference() {
// named range list
String namedRange = "MyNamedRange";
DataValidationConstraint constraint = new XSSFDataValidationConstraint(listType, ignoredType, namedRange, null);
assertNull(constraint.getExplicitListValues());
assertEquals("MyNamedRange", constraint.getFormula1());
}
use of org.apache.poi.ss.usermodel.DataValidationConstraint in project poi by apache.
the class TestXSSFDataValidationConstraint method listLiteralsQuotesAreStripped_formulaConstructor.
// See bug 59719
@Test
public void listLiteralsQuotesAreStripped_formulaConstructor() {
// literal list, using formula constructor
String literal = "\"one, two, three\"";
String[] expected = new String[] { "one", "two", "three" };
DataValidationConstraint constraint = new XSSFDataValidationConstraint(listType, ignoredType, literal, null);
assertArrayEquals(expected, constraint.getExplicitListValues());
// Excel and DataValidationConstraint parser ignore (strip) whitespace; quotes should still be intact
// FIXME: whitespace wasn't stripped
assertEquals(literal, constraint.getFormula1());
}
use of org.apache.poi.ss.usermodel.DataValidationConstraint in project poi by apache.
the class TestXSSFDataValidationConstraint method rangeReference.
@Test
public void rangeReference() {
// (unnamed range) reference list
String reference = "A1:A5";
DataValidationConstraint constraint = new XSSFDataValidationConstraint(listType, ignoredType, reference, null);
assertNull(constraint.getExplicitListValues());
assertEquals("A1:A5", constraint.getFormula1());
}
Aggregations