Bug 51870

Summary: [PATCH] Allow HSSFSheet to query existing DataValidation settings
Product: POI Reporter: Hannes Erven <hannes>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: enhancement CC: yoann.rodiere
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Patch.

Description Hannes Erven 2011-09-22 16:09:11 UTC
Created attachment 27567 [details]
Patch.

I need to detect whether a given HSSFSheet already has DataValidation settings applied.
The DataValidityTable class already has a visitContainedRecords(RecordVisitor) method, that is currently inaccessible from both HSSFSheet and user code.

The following patch suggests to add a method 

public void visitValidationData(RecordVisitor rv)

to HSSFSheet to iterate through the DataValidation records.
Use it like this:

final RecordVisitor rv = new RecordVisitor() {
  @Override
  public void visitRecord(Record r) {
    if (r instanceof DVRecord){
      final DVRecord dr = (DVRecord) r;
      // So there's the validation
      if (dr.getDataType() == ValidationType.LIST){
           // There is a DROP DOWN list! Use dr.* to examine location and content.
      }
    }
  }
};
sheet.visitValidationData(rv);



The XSSFSheet already provides a getDataValidations() method,
Comment 1 Yegor Kozlov 2013-10-26 10:38:46 UTC
Unfortunately the path in its current form cannot be applied.

HSSF does not expose classes for internal use: there are no getters that return record.* or model.* objects, these are hidden and it is by design. 

Think about implementing getDataValidations() in HSSFSheet. That would be cool and this method will go to the interface:

In the Sheet interface we will have  List<DataValidation> getDataValidations() 

and two implementations:

 List<HSSHDataValidation> getDataValidations()  
 List<XSSFDataValidation> getDataValidations() 

Regards,
Yegor
Comment 2 Dominik Stadler 2015-05-31 21:58:08 UTC
This method is available since some time already, therefore resolving this as FIXED.