Adding data validation to XSSF sheet using POI causes "Excel found
unreadable content..." error
I have a class which successfully creates and saves the excelsheet.
Everything works fine. But when I tried adding data validation to the
sheet, I get the "Excel found unreadable content in "xyz.xlsx". Do you
want to recover contents of this workbook? If you trust the source of this
workbook, click Yes."
Once I click yes, I can view the excel with the dropdowns. It looks good.
I am unable to figure out what I'm doing wrong here.
These are the lines I added which cause this error.
private final String [] actions = new String[] { "4", "3", "2", "1" };
dvHelper = new XSSFDataValidationHelper(sheet);
constraint = (XSSFDataValidationConstraint)
dvHelper.createExplicitListConstraint(actions);
CellRangeAddressList addressList = new CellRangeAddressList(iniRowCount,
0, ExcelConstants.CELL_EIGHT, 0);
XSSFDataValidation validation = (XSSFDataValidation)
dvHelper.createValidation(constraint, addressList);
validation.setShowErrorBox(true);
sheet.addValidationData(validation);
cell.setCellValue("default_value");
If i run the code without the above lines commented, the excel is
readable, and the cell has the default value.
No comments:
Post a Comment