Search in sources :

Example 1 with CellRangeAddressBase

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

the class DataValidationEvaluator method getValidationContextForCell.

/**
     * Finds and returns the {@link DataValidationContext} for the cell, if there is
     * one. Lookup is based on the first match from
     * {@link DataValidation#getRegions()} for the cell's sheet. DataValidation
     * regions must be in the same sheet as the DataValidation. Allowed values
     * expressions may reference other sheets, however.
     * 
     * @param cell reference to check
     * @return the DataValidationContext applicable to the given cell, or null if no
     *         validation applies
     */
public DataValidationContext getValidationContextForCell(CellReference cell) {
    final Sheet sheet = workbook.getSheet(cell.getSheetName());
    if (sheet == null)
        return null;
    final List<? extends DataValidation> dataValidations = getValidations(sheet);
    if (dataValidations == null)
        return null;
    for (DataValidation dv : dataValidations) {
        final CellRangeAddressList regions = dv.getRegions();
        if (regions == null)
            return null;
        // current implementation can't return null
        for (CellRangeAddressBase range : regions.getCellRangeAddresses()) {
            if (range.isInRange(cell)) {
                return new DataValidationContext(dv, this, range, cell);
            }
        }
    }
    return null;
}
Also used : CellRangeAddressBase(org.apache.poi.ss.util.CellRangeAddressBase) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) Sheet(org.apache.poi.ss.usermodel.Sheet) DataValidation(org.apache.poi.ss.usermodel.DataValidation)

Example 2 with CellRangeAddressBase

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

the class TestHSSFChart method testExistingSheet1.

@Test
public void testExistingSheet1() throws Exception {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFChart[] charts = HSSFChart.getSheetCharts(sheet);
    for (HSSFChart chart : charts) {
        //System.out.println( chart.getType() ) ;
        HSSFSeries[] seriesArray = chart.getSeries();
        //System.out.println( "seriesArray.length=" + seriesArray.length ) ;
        for (HSSFSeries series : seriesArray) {
            //System.out.println( "serie.getNumValues()=" + series.getNumValues() ) ;
            CellRangeAddressBase range;
            range = series.getValuesCellRange();
            //System.out.println( range.toString() ) ;
            range.setLastRow(range.getLastRow() + 1);
            series.setValuesCellRange(range);
            range = series.getCategoryLabelsCellRange();
            //System.out.println( range.toString() ) ;
            range.setLastRow(range.getLastRow() + 1);
            series.setCategoryLabelsCellRange(range);
        }
        for (int id = 0; id < 2; id++) {
            HSSFSeries newSeries = chart.createSeries();
            newSeries.setValuesCellRange(new CellRangeAddress(1 + id, 4, 3, 3));
            String oldSeriesTitle = newSeries.getSeriesTitle();
            if (oldSeriesTitle != null) {
                //System.out.println( "old series title: " + oldSeriesTitle ) ;
                newSeries.setSeriesTitle("new series");
            }
        }
    }
    HSSFChart chart = charts[2];
    chart.removeSeries(chart.getSeries()[0]);
}
Also used : HSSFSeries(org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries) CellRangeAddressBase(org.apache.poi.ss.util.CellRangeAddressBase) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Test(org.junit.Test)

Aggregations

CellRangeAddressBase (org.apache.poi.ss.util.CellRangeAddressBase)2 HSSFSeries (org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries)1 DataValidation (org.apache.poi.ss.usermodel.DataValidation)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 CellRangeAddressList (org.apache.poi.ss.util.CellRangeAddressList)1 Test (org.junit.Test)1