You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Borut Žagar <bo...@gmail.com> on 2009/06/11 10:28:04 UTC

HSSF, protected workbook, data validation

Hi!

I am using POI final 3.2, and I am creating a worksheet which I want it to
be
protected (certain cells cannot be edited).

But I am getting an exception when adding a data validation to the
worksheet.
The exception is:

java.lang.IllegalStateException: Unexpected
(org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table
insert pos
    at
org.apache.poi.hssf.model.RecordOrderer.findDataValidationTableInsertPos(RecordOrderer.java:240)
    at
org.apache.poi.hssf.model.RecordOrderer.findSheetInsertPos(RecordOrderer.java:95)
    at
org.apache.poi.hssf.model.RecordOrderer.addNewSheetRecord(RecordOrderer.java:89)
    at
org.apache.poi.hssf.model.Sheet.getOrCreateDataValidityTable(Sheet.java:1752)
    at
org.apache.poi.hssf.usermodel.HSSFSheet.addValidationData(HSSFSheet.java:369)
    at
com.cmpny.product.bl.pr.PremiumsImporterExporterBL.addInputTypeDropdown(PremiumsImporterExporterBL.java:163)


The code for adding data validation object is:

CellRangeAddressList cral = new CellRangeAddressList(1, 1, 1, 1);
HSSFDataValidation dataValidation =
    new HSSFDataValidation(cral,
DVConstraint.createExplicitListConstraint(new
String[] {"one", "two"}));
dataValidation.setEmptyCellAllowed(false);
dataValidation.setSuppressDropDownArrow(false);
dataValidation.setShowPromptBox(false);
dataValidation.createErrorBox("Wrong value", "Please select from list.");
wb.getCurrentSheet().addValidationData(dataValidation);


If I remove worksheet protection or remove adding of data validation object
to
workbook it all works fine so it seems that both together are not working.

Regards, Borut

Re: HSSF, protected workbook, data validation

Posted by Josh Micich <jo...@gmail.com>.
Thanks for the bug report.  Fixed in svn trunk. Here is the bugzilla entry:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47363

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: HSSF, protected workbook, data validation

Posted by Borut <bo...@gmail.com>.
MSB <markbrdsly <at> tiscali.co.uk> writes:

> 
> 
> Forgive me if this is a stupid question but what order are you doing the
> operations in? Are you adding the validation and then protecting the sheet
> or protecting the sheet and then adding the validation?
> 
> I have no idea if it matters at all but it could be that, if you are
> protecting the sheet and then adding the validation, that this is the source
> of the problem.
> 
> Yours
> 
> Mark B



You are right, if I apply protection to the sheet after adding data validation
all works well. Funny, this should be documented! :)

Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: HSSF, protected workbook, data validation

Posted by MSB <ma...@tiscali.co.uk>.
Forgive me if this is a stupid question but what order are you doing the
operations in? Are you adding the validation and then protecting the sheet
or protecting the sheet and then adding the validation?

I have no idea if it matters at all but it could be that, if you are
protecting the sheet and then adding the validation, that this is the source
of the problem.

Yours

Mark B


Borut Žagar wrote:
> 
> Hi!
> 
> I am using POI final 3.2, and I am creating a worksheet which I want it to
> be
> protected (certain cells cannot be edited).
> 
> But I am getting an exception when adding a data validation to the
> worksheet.
> The exception is:
> 
> java.lang.IllegalStateException: Unexpected
> (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table
> insert pos
>     at
> org.apache.poi.hssf.model.RecordOrderer.findDataValidationTableInsertPos(RecordOrderer.java:240)
>     at
> org.apache.poi.hssf.model.RecordOrderer.findSheetInsertPos(RecordOrderer.java:95)
>     at
> org.apache.poi.hssf.model.RecordOrderer.addNewSheetRecord(RecordOrderer.java:89)
>     at
> org.apache.poi.hssf.model.Sheet.getOrCreateDataValidityTable(Sheet.java:1752)
>     at
> org.apache.poi.hssf.usermodel.HSSFSheet.addValidationData(HSSFSheet.java:369)
>     at
> com.cmpny.product.bl.pr.PremiumsImporterExporterBL.addInputTypeDropdown(PremiumsImporterExporterBL.java:163)
> 
> 
> The code for adding data validation object is:
> 
> CellRangeAddressList cral = new CellRangeAddressList(1, 1, 1, 1);
> HSSFDataValidation dataValidation =
>     new HSSFDataValidation(cral,
> DVConstraint.createExplicitListConstraint(new
> String[] {"one", "two"}));
> dataValidation.setEmptyCellAllowed(false);
> dataValidation.setSuppressDropDownArrow(false);
> dataValidation.setShowPromptBox(false);
> dataValidation.createErrorBox("Wrong value", "Please select from list.");
> wb.getCurrentSheet().addValidationData(dataValidation);
> 
> 
> If I remove worksheet protection or remove adding of data validation
> object
> to
> workbook it all works fine so it seems that both together are not working.
> 
> Regards, Borut
> 
> 

-- 
View this message in context: http://www.nabble.com/HSSF%2C-protected-workbook%2C-data-validation-tp23977349p23987275.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org