You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by ravindra reddy <ma...@gmail.com> on 2013/02/13 10:59:36 UTC

Problem using datavalidation with explict list constraint

Hi,

am using Apache POI for adding drop down list for cell with data
validation..

I am using the below code.

          XSSFWorkbook workbook = new XSSFWorkbook();
          XSSFSheet sheet = workbook.createSheet("Data Validation");
          XSSFDataValidationHelper dvHelper = new
XSSFDataValidationHelper(sheet);
          List<String> a=new ArrayList<String>();;
          a.add("abc,def");a.add("AA");a.add("nei");
          XSSFDataValidationConstraint dvConstraint =
(XSSFDataValidationConstraint)
            dvHelper.createExplicitListConstraint(a.toArray(new
String[a.size()]));
          CellRangeAddressList addressList = new CellRangeAddressList(0, 0,
0, 0);
          XSSFDataValidation validation =
(XSSFDataValidation)dvHelper.createValidation(
            dvConstraint, addressList);
          validation.setShowErrorBox(true);
          sheet.addValidationData(validation);
           XSSFCell cell=sheet.createRow(0).createCell(0);
           cell.setCellValue("gg");

          FileOutputStream fos=new FileOutputStream("test.xlsx");
          workbook.write(fos);


The problem is " the first value "abc,def" is coming as two values in drop
down list .........list abc and def

I am trying to find how can I represent comma in list value rather than
separator..

thanks
ravindra

Re: Problem using datavalidation with explict list constraint

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Sorry top say that this is a limitation imposed by Excel, not by POI; if you
try to do something like this using Excel, it will also create separate
entries for the comma separated items. Also, as far as I am aware, there is
no way to escape the comma in the list.

To my mind, you have two options. Option one is to create the validation
from the contents of cells. In that way, one of the cells could contain a
string such as A, B and be included in the validation. The second option is
to replace the comma with ascii character 130. This is not the comma but it
does look very like it.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Problem-using-datavalidation-with-explict-list-constraint-tp5712093p5712102.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