Search in sources :

Example 1 with RecordVisitor

use of org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor in project poi by apache.

the class TestValueRecordsAggregate method confirmMulBlank.

private void confirmMulBlank(int expectedTotalBlankCells, int expectedNumberOfMulBlankRecords, int expectedNumberOfSingleBlankRecords) {
    // assumed row ranges set-up by caller:
    final int firstRow = 1;
    final int lastRow = 2;
    final class BlankStats {

        public int countBlankCells;

        public int countMulBlankRecords;

        public int countSingleBlankRecords;
    }
    final BlankStats bs = new BlankStats();
    RecordVisitor rv = new RecordVisitor() {

        @Override
        public void visitRecord(Record r) {
            if (r instanceof MulBlankRecord) {
                MulBlankRecord mbr = (MulBlankRecord) r;
                bs.countMulBlankRecords++;
                bs.countBlankCells += mbr.getNumColumns();
            } else if (r instanceof BlankRecord) {
                bs.countSingleBlankRecords++;
                bs.countBlankCells++;
            }
        }
    };
    for (int rowIx = firstRow; rowIx <= lastRow; rowIx++) {
        if (valueRecord.rowHasCells(rowIx)) {
            valueRecord.visitCellsForRow(rowIx, rv);
        }
    }
    assertEquals(expectedTotalBlankCells, bs.countBlankCells);
    assertEquals(expectedNumberOfMulBlankRecords, bs.countMulBlankRecords);
    assertEquals(expectedNumberOfSingleBlankRecords, bs.countSingleBlankRecords);
}
Also used : MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) Record(org.apache.poi.hssf.record.Record) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) RecordVisitor(org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor)

Example 2 with RecordVisitor

use of org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor in project poi by apache.

the class HSSFSheet method getDataValidations.

@Override
public List<HSSFDataValidation> getDataValidations() {
    DataValidityTable dvt = _sheet.getOrCreateDataValidityTable();
    final List<HSSFDataValidation> hssfValidations = new ArrayList<HSSFDataValidation>();
    RecordVisitor visitor = new RecordVisitor() {

        private HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(getWorkbook());

        @Override
        public void visitRecord(Record r) {
            if (!(r instanceof DVRecord)) {
                return;
            }
            DVRecord dvRecord = (DVRecord) r;
            CellRangeAddressList regions = dvRecord.getCellRangeAddress().copy();
            DVConstraint constraint = DVConstraint.createDVConstraint(dvRecord, book);
            HSSFDataValidation hssfDataValidation = new HSSFDataValidation(regions, constraint);
            hssfDataValidation.setErrorStyle(dvRecord.getErrorStyle());
            hssfDataValidation.setEmptyCellAllowed(dvRecord.getEmptyCellAllowed());
            hssfDataValidation.setSuppressDropDownArrow(dvRecord.getSuppressDropdownArrow());
            hssfDataValidation.createPromptBox(dvRecord.getPromptTitle(), dvRecord.getPromptText());
            hssfDataValidation.setShowPromptBox(dvRecord.getShowPromptOnCellSelected());
            hssfDataValidation.createErrorBox(dvRecord.getErrorTitle(), dvRecord.getErrorText());
            hssfDataValidation.setShowErrorBox(dvRecord.getShowErrorOnInvalidValue());
            hssfValidations.add(hssfDataValidation);
        }
    };
    dvt.visitContainedRecords(visitor);
    return hssfValidations;
}
Also used : DVRecord(org.apache.poi.hssf.record.DVRecord) ArrayList(java.util.ArrayList) SCLRecord(org.apache.poi.hssf.record.SCLRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) Record(org.apache.poi.hssf.record.Record) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) AutoFilterInfoRecord(org.apache.poi.hssf.record.AutoFilterInfoRecord) DVRecord(org.apache.poi.hssf.record.DVRecord) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) DataValidityTable(org.apache.poi.hssf.record.aggregates.DataValidityTable) RecordVisitor(org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor)

Aggregations

Record (org.apache.poi.hssf.record.Record)2 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)2 RecordVisitor (org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor)2 ArrayList (java.util.ArrayList)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 AutoFilterInfoRecord (org.apache.poi.hssf.record.AutoFilterInfoRecord)1 BlankRecord (org.apache.poi.hssf.record.BlankRecord)1 DVRecord (org.apache.poi.hssf.record.DVRecord)1 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)1 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)1 ExtendedFormatRecord (org.apache.poi.hssf.record.ExtendedFormatRecord)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 HyperlinkRecord (org.apache.poi.hssf.record.HyperlinkRecord)1 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)1 NameRecord (org.apache.poi.hssf.record.NameRecord)1 RowRecord (org.apache.poi.hssf.record.RowRecord)1 SCLRecord (org.apache.poi.hssf.record.SCLRecord)1 SharedFormulaRecord (org.apache.poi.hssf.record.SharedFormulaRecord)1 WSBoolRecord (org.apache.poi.hssf.record.WSBoolRecord)1 DataValidityTable (org.apache.poi.hssf.record.aggregates.DataValidityTable)1