Bug 51870 - [PATCH] Allow HSSFSheet to query existing DataValidation settings
Summary: [PATCH] Allow HSSFSheet to query existing DataValidation settings
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-22 16:09 UTC by Hannes Erven
Modified: 2015-05-31 21:58 UTC (History)
1 user (show)



Attachments
Patch. (1.90 KB, application/octet-stream)
2011-09-22 16:09 UTC, Hannes Erven
Details

Note You need to log in before you can comment on or make changes to this bug.
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.