Search in sources :

Example 16 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class CFHeaderBase method setCellRanges.

/**
     * Set cell ranges list to a single cell range and 
     * modify the enclosing cell range accordingly.
     * @param cellRanges - list of CellRange objects
     */
public void setCellRanges(CellRangeAddress[] cellRanges) {
    if (cellRanges == null) {
        throw new IllegalArgumentException("cellRanges must not be null");
    }
    CellRangeAddressList cral = new CellRangeAddressList();
    CellRangeAddress enclosingRange = null;
    for (int i = 0; i < cellRanges.length; i++) {
        CellRangeAddress cr = cellRanges[i];
        enclosingRange = CellRangeUtil.createEnclosingCellRange(cr, enclosingRange);
        cral.addCellRangeAddress(cr);
    }
    field_3_enclosing_cell_range = enclosingRange;
    field_4_cell_ranges = cral;
}
Also used : CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 17 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class TestSXSSFDataValidation method test53965.

@Test
public void test53965() throws Exception {
    SXSSFWorkbook wb = new SXSSFWorkbook();
    try {
        Sheet sheet = wb.createSheet();
        //<-- works
        List<? extends DataValidation> 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) Sheet(org.apache.poi.ss.usermodel.Sheet) DataValidation(org.apache.poi.ss.usermodel.DataValidation) BaseTestDataValidation(org.apache.poi.ss.usermodel.BaseTestDataValidation) Test(org.junit.Test)

Example 18 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class TestDataValidation method testGetDataValidationsIntegerFormula.

@Test
public void testGetDataValidationsIntegerFormula() throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    List<HSSFDataValidation> list = sheet.getDataValidations();
    assertEquals(0, list.size());
    DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
    DataValidationConstraint constraint = dataValidationHelper.createIntegerConstraint(OperatorType.BETWEEN, "=A2", "=A3");
    CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
    DataValidation validation = dataValidationHelper.createValidation(constraint, addressList);
    sheet.addValidationData(validation);
    // <-- works
    list = sheet.getDataValidations();
    assertEquals(1, list.size());
    HSSFDataValidation dv = list.get(0);
    DVConstraint c = dv.getConstraint();
    assertEquals(ValidationType.INTEGER, c.getValidationType());
    assertEquals(OperatorType.BETWEEN, c.getOperator());
    assertEquals("A2", c.getFormula1());
    assertEquals("A3", c.getFormula2());
    assertEquals(null, c.getValue1());
    assertEquals(null, c.getValue2());
    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 19 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class TestDataValidation method testGetDataValidationsListExplicit.

@Test
public void testGetDataValidationsListExplicit() throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    List<HSSFDataValidation> list = sheet.getDataValidations();
    assertEquals(0, list.size());
    DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
    DataValidationConstraint constraint = dataValidationHelper.createExplicitListConstraint(new String[] { "aaa", "bbb", "ccc" });
    CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
    DataValidation validation = dataValidationHelper.createValidation(constraint, addressList);
    validation.setSuppressDropDownArrow(true);
    sheet.addValidationData(validation);
    // <-- works
    list = sheet.getDataValidations();
    assertEquals(1, list.size());
    HSSFDataValidation dv = list.get(0);
    assertEquals(true, dv.getSuppressDropDownArrow());
    DVConstraint c = dv.getConstraint();
    assertEquals(ValidationType.LIST, c.getValidationType());
    assertEquals(null, c.getFormula1());
    assertEquals(null, c.getFormula2());
    assertEquals(null, c.getValue1());
    assertEquals(null, c.getValue2());
    String[] values = c.getExplicitListValues();
    assertEquals(3, values.length);
    assertEquals("aaa", values[0]);
    assertEquals("bbb", values[1]);
    assertEquals("ccc", values[2]);
    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 20 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class TestDataValidation method testGetDataValidationsIntegerValue.

@Test
public void testGetDataValidationsIntegerValue() throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    List<HSSFDataValidation> list = sheet.getDataValidations();
    assertEquals(0, list.size());
    DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
    DataValidationConstraint constraint = dataValidationHelper.createIntegerConstraint(OperatorType.BETWEEN, "100", "200");
    CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
    DataValidation validation = dataValidationHelper.createValidation(constraint, addressList);
    sheet.addValidationData(validation);
    // <-- works
    list = sheet.getDataValidations();
    assertEquals(1, list.size());
    HSSFDataValidation dv = list.get(0);
    DVConstraint c = dv.getConstraint();
    assertEquals(ValidationType.INTEGER, c.getValidationType());
    assertEquals(OperatorType.BETWEEN, c.getOperator());
    assertEquals(null, c.getFormula1());
    assertEquals(null, c.getFormula2());
    assertEquals(new Double("100"), c.getValue1());
    assertEquals(new Double("200"), c.getValue2());
    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)

Aggregations

CellRangeAddressList (org.apache.poi.ss.util.CellRangeAddressList)25 Test (org.junit.Test)15 DataValidationConstraint (org.apache.poi.ss.usermodel.DataValidationConstraint)14 DataValidation (org.apache.poi.ss.usermodel.DataValidation)13 DataValidationHelper (org.apache.poi.ss.usermodel.DataValidationHelper)13 BaseTestDataValidation (org.apache.poi.ss.usermodel.BaseTestDataValidation)12 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)6 Sheet (org.apache.poi.ss.usermodel.Sheet)4 BigDecimal (java.math.BigDecimal)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Row (org.apache.poi.ss.usermodel.Row)2 CellReference (org.apache.poi.ss.util.CellReference)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 AssertionFailedError (junit.framework.AssertionFailedError)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1