0

我有一个 excel 文档,用户使用它根据模板输入数据并上传回来。现在我在工作簿中有很多工作表,每张工作表都有许多具有不同验证的单元格。

Validations like:
1. The cell data should be only numeric
2. The cell data should be in a specific format xxx-xxx
3. The cell data should be a date in yyyy-mm-dd format

ETC...

他们有一个可以完成这项工作的框架吗?就像我只需要配置单元格中允许的数据(使用正则表达式等),框架将负责验证。

4

2 回答 2

0

有一些框架可以从 Java 访问 Excel 文件。像Apache POI。但我不知道有一个框架可以满足你的描述。

也许最好将此验证添加到 excel 文件中,以便用户无法输入无效数据。

于 2013-03-19T14:30:11.573 回答
0

在服务器中验证 excel 文件上传时存在几个问题。尽管可以使用 if else 条件来完成,例如:

  1. 单元格数据只能是数字
if (cell.getCellType() != CellType.NUMERIC) {
  // throw exception or print print help message
}
  1. 单元格数据应为 yyyy-mm-dd 格式的日期
if (!DateUtil.isCellDateFormatted(cell)) {
  // throw exception or print print help message
}

但是,验证 Date 类型的单元格和应用正则表达式是很棘手的。

于 2020-11-26T01:16:19.977 回答