use of org.apache.poi.hssf.record.aggregates.DataValidityTable in project poi by apache.
the class InternalSheet method getOrCreateDataValidityTable.
public DataValidityTable getOrCreateDataValidityTable() {
if (_dataValidityTable == null) {
DataValidityTable result = new DataValidityTable();
RecordOrderer.addNewSheetRecord(_records, result);
_dataValidityTable = result;
}
return _dataValidityTable;
}
use of org.apache.poi.hssf.record.aggregates.DataValidityTable in project poi by apache.
the class RecordOrderer method findInsertPosForNewCondFormatTable.
/**
* Find correct position to add new CFHeader record
*/
private static int findInsertPosForNewCondFormatTable(List<RecordBase> records) {
for (int i = records.size() - 2; i >= 0; i--) {
// -2 to skip EOF record
Object rb = records.get(i);
if (rb instanceof MergedCellsTable) {
return i + 1;
}
if (rb instanceof DataValidityTable) {
continue;
}
Record rec = (Record) rb;
switch(rec.getSid()) {
case WindowTwoRecord.sid:
case SCLRecord.sid:
case PaneRecord.sid:
case SelectionRecord.sid:
case UnknownRecord.STANDARDWIDTH_0099:
// MergedCellsTable usually here
case UnknownRecord.LABELRANGES_015F:
case UnknownRecord.PHONETICPR_00EF:
// ConditionalFormattingTable goes here
return i + 1;
}
}
throw new RuntimeException("Did not find Window2 record");
}
use of org.apache.poi.hssf.record.aggregates.DataValidityTable in project poi by apache.
the class HSSFSheet method addValidationData.
/**
* Creates a data validation object
*
* @param dataValidation The Data validation object settings
*/
@Override
public void addValidationData(DataValidation dataValidation) {
if (dataValidation == null) {
throw new IllegalArgumentException("objValidation must not be null");
}
HSSFDataValidation hssfDataValidation = (HSSFDataValidation) dataValidation;
DataValidityTable dvt = _sheet.getOrCreateDataValidityTable();
DVRecord dvRecord = hssfDataValidation.createDVRecord(this);
dvt.addDataValidation(dvRecord);
}
use of org.apache.poi.hssf.record.aggregates.DataValidityTable 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