I recently found the problem here.

The code doesn't show the error whenever the user enters an invalid data.

|XSSFDataValidationHelper  dvHelper=  new  XSSFDataValidationHelper(
                destinationSheet);
XSSFDataValidationConstraint  dvConstraint=  (XSSFDataValidationConstraint)  
dvHelper
                .createIntegerConstraint(OperatorType.EQUAL,  "0",  "10");
CellRangeAddressList  addressList=  new  CellRangeAddressList(7,
                destinationSheet.getLastRowNum()  +  1,  9,  destinationSheet
                        .getRow(0).getLastCellNum());
XSSFDataValidation  validation=  (XSSFDataValidation)  dvHelper
                .createValidation(dvConstraint,  addressList);

validation.setErrorStyle(ErrorStyle.STOP);
validation.createErrorBox("Error",  "Only numeric values are allowed");
validation.setShowErrorBox(true);  // The code is missing this line

destinationSheet.addValidationData(validation);|

The implementation in XSSF is different from HSSF which on the other hand doesn't need the line |validation.setShowErrorBox(true);| to work. I've used HSSF in my previous implementation which result to not setting the showErrorBox to true.



On 9/25/2013 2:08 PM, Michael Ardan wrote:
Hi Everyone!

Good day!

I was wondering if it is possible to restrict the user from inputting an alphabet character in a cell via Apache POI.

I tried the following code but the cell is still accepting an alphabet character. (Reference: Busy Developer)

|XSSFDataValidationHelper  dvHelper=  new  
XSSFDataValidationHelper(destinationSheet);
XSSFDataValidationConstraint  dvConstraint=  (XSSFDataValidationConstraint)  
dvHelper.createIntegerConstraint(OperatorType.GREATER_THAN,  "0",  "0");
CellRangeAddressList  addressList=  new  
CellRangeAddressList(7,destinationSheet.getLastRowNum()  +  1,  9,  
destinationSheet.getRow(0).getLastCellNum());
XSSFDataValidation  validation=  (XSSFDataValidation)  
dvHelper.createValidation(dvConstraint,  addressList);

validation.setErrorStyle(ErrorStyle.STOP);
validation.createErrorBox("Error",  "Only numeric values are allowed");

destinationSheet.addValidationData(validation);
|

--
*Michael Ardan*
Jr Analyst/Developer
*eScience Corporation*
Tel (632) 8501324
Fax (632) 8427408
Mobile (63) 926-3145737
YM [email protected]

/This e-mail message (including attachments, if any) is intended for the use of the individual or the entity to whom it is addressed and may contain information that is privileged, proprietary, confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender and delete this E-mail message immediately./


--
*Michael Ardan*
Jr Analyst/Developer
*eScience Corporation*
Tel (632) 8501324
Fax (632) 8427408
Mobile (63) 926-3145737
YM [email protected]

/This e-mail message (including attachments, if any) is intended for the use of the individual or the entity to whom it is addressed and may contain information that is privileged, proprietary, confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender and delete this E-mail message immediately./

Reply via email to