# excel-tool
**Repository Path**: XiaoCui1/excel-tool
## Basic Information
- **Project Name**: excel-tool
- **Description**: 支持导入2003/2007版本的excel,通过配置文件配置校验字段方式。支持反馈消息按行或列分组展示。
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2020-02-24
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
### Excel校验数据并导入
准备工作:
- 导入依赖
```java
com.lineit
excel-tool
1.0.0
```
- 配置excel数据校验规则与校验信息的xml
```xml
列名1
正则表达式
错误信息
列名2
正则表达式
错误信息
```
- 调用方法
```java
/**
* @param path xml配置文件路径
* @param beginRow excel表头行数(excel行数从0开始)
* @param file 客户端传来的文件
*/
Map result = PoiUtil.readExcel(String path, int beginRow, MultipartFile file);
```
```json
//excel导入正常返回数据结构
{
"data": [
{
"租金调整": "1",
"合同编号": "12",
"供应商": "温州市建源贸易有限公司",
"经营品牌(专柜)": "12334",
"做账时间": "2020-02-07"
},
{
"合同编号": "21",
"供应商": "宁波市镇海兴商物资有限公司",
"经营品牌(专柜)": "12334",
"做账时间": "2020-02-07"
},
{
"合同编号": "32",
"供应商": "张福明",
"经营品牌(专柜)": "12334",
"做账时间": "2020-02-07"
},
{
"合同编号": "32",
"供应商": "王晓红",
"经营品牌(专柜)": "12334",
"做账时间": "2020-02-07"
},
{
"合同编号": "32",
"供应商": "王晓红",
"经营品牌(专柜)": "12334",
"做账时间": "2020-02-07"
},
{
"合同编号": "32",
"供应商": "宁波江东名莎国际贸易有限公司",
"经营品牌(专柜)": "12334",
"做账时间": "2020-02-07"
}
],
"validate": true
}
```
```json
//excel导入数据异常以列分组结果
{
"data": {
"合同编号不能为空,且必须为数字": "3\n5",
"经营品牌(专柜)必须为数字或字母,只能为4~6位": "1\n2\n3\n4\n5\n6"
},
"validate": false
}
```
```json
//excel导入数据异常以行分组结果
{
"data": {
"1": "经营品牌(专柜)必须为数字或字母,只能为4~6位",
"2": "经营品牌(专柜)必须为数字或字母,只能为4~6位",
"3": "合同编号不能为空,且必须为数字\n经营品牌(专柜)必须为数字或字母,只能为4~6位",
"4": "经营品牌(专柜)必须为数字或字母,只能为4~6位",
"5": "合同编号不能为空,且必须为数字\n经营品牌(专柜)必须为数字或字母,只能为4~6位",
"6": "经营品牌(专柜)必须为数字或字母,只能为4~6位"
},
"validate": false
}
```
```java
//校验不通过组装反馈消息并返回
if(map.get("validate").equals(false)){
String error = PoiUtil.getErrorMsg(map);
result.put("ret", -1);
result.put("desc", error);
return result;
}
```