Search in sources :

Example 16 with DataValidationConstraint

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();
    }
}
Also used : DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) DataValidationHelper(org.apache.poi.ss.usermodel.DataValidationHelper) DataValidation(org.apache.poi.ss.usermodel.DataValidation) BaseTestDataValidation(org.apache.poi.ss.usermodel.BaseTestDataValidation) Test(org.junit.Test)

Example 17 with DataValidationConstraint

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());
}
Also used : DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) Test(org.junit.Test)

Example 18 with DataValidationConstraint

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());
}
Also used : DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) Test(org.junit.Test)

Example 19 with DataValidationConstraint

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());
}
Also used : DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) Test(org.junit.Test)

Example 20 with DataValidationConstraint

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());
}
Also used : DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) Test(org.junit.Test)

Aggregations

DataValidationConstraint (org.apache.poi.ss.usermodel.DataValidationConstraint)20 Test (org.junit.Test)16 CellRangeAddressList (org.apache.poi.ss.util.CellRangeAddressList)14 DataValidationHelper (org.apache.poi.ss.usermodel.DataValidationHelper)13 BaseTestDataValidation (org.apache.poi.ss.usermodel.BaseTestDataValidation)12 DataValidation (org.apache.poi.ss.usermodel.DataValidation)12 Sheet (org.apache.poi.ss.usermodel.Sheet)3 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)3 ArrayList (java.util.ArrayList)2 Row (org.apache.poi.ss.usermodel.Row)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 AssertionFailedError (junit.framework.AssertionFailedError)1 HSSFDataValidation (org.apache.poi.hssf.usermodel.HSSFDataValidation)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 StringEval (org.apache.poi.ss.formula.eval.StringEval)1 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellReference (org.apache.poi.ss.util.CellReference)1