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);
}
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;
}
Aggregations