Controller中接收form表单提交的文件域:
public Map importConsumer(@RequestParam("file") MultipartFile file)
读取Excel工具类 这里我以Consumer实体类来写,大家可以自行封装:
public class ReadExcel
{
// 总行数
private int totalRows = 0;
// 总条数
private int totalCells = 0;
// 错误信息接收器
private String errorMsg;
// 构造方法
public ReadExcel()
{
}
// 获取总行数
public int getTotalRows()
{
return totalRows;
}
// 获取总列数
public int getTotalCells()
{
return totalCells;
}
// 获取错误信息
public String getErrorInfo()
{
return errorMsg;
}
/**
* 验证EXCEL文件
*
* @param filePath
* @return
*/
public boolean validateExcel(String filePath)
{
if(filePath == null || !(WDWUtil.isExcel2003(filePath) || WDWUtil.isExcel2007(filePath)))
{
errorMsg = "文件名不是excel格式";
return false;
}
return true;
}
/**
* 读EXCEL文件,获取客户信息集合
*
* @param fielName
* @