1

我需要检查用户是否在单元格 A1:A10 中输入了有效数字。在 Excel 中,我会选择单元格,然后创建自定义验证器并将公式设置为 =isNumber("$A$1:$A10") 尝试使用 POI 执行此操作让我陷入困境:这是我尝试过的:

CellRangeAddressList addressList = new CellRangeAddressList(0, 10, 0, 0);
        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
        DataValidationConstraint customConstraint = dvHelper.createCustomConstraint("isNumber(\"$A$0:$A$10\"");
        XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(customConstraint, addressList);
        validation.setShowErrorBox(true);
        sheet.addValidationData(validation);

当我尝试在 Excel 中打开它时,出现错误,并且 Excel 禁用了验证

在此先感谢-anish

4

2 回答 2

0
CellReference crStartCell = new CellReference(startRow, column, true, true); // 0-based row and column index
CellReference crEndCell = new CellReference(endRow, column, true, true);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createCustomConstraint("ISNUMBER("+crStartCell.formatAsString()+":"+crEndCell.formatAsString() +")");
于 2013-08-22T14:48:22.567 回答
0

您可以将该 excel 转换为 csv,而不是使用 SuperCSV 执行验证。它会很长,但更容易。

于 2013-08-23T08:39:43.647 回答