java实现将Excel表格中的数据读取出来并存放到数据库中,此类的作用只是将Excel表格中的数据读取出来存放map集合中。有些方法也借鉴了百度大神的博客,如果有侵权,请速与我联系,我将马上删除
import com.alibaba.druid.sql.visitor.functions.Char;
import com.github.pagehelper.util.StringUtil;
import com.hyzh.security.supervise.entity.ClassSchedule;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @description 解析excel表中的数据,此工具类只适用于特定sup_class_provision表
* @Author
* @Date 2019/12/18
*/
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文件,获取信息集合
* @return
*/
public Map<String, Object> getExcelInfo(MultipartFile mFile) {
//List<ClassSchedule> classScheduleList = new ArrayList<ClassSchedule>();
Map<String, Object> map = new HashMap<>();
String fileName = mFile.getOriginalFilename();//获取文件名
try {
if (!validateExcel(fileName)) {// 验证文件名是否合格
return null;
}
boolean isExcel2003 = true;// 根据文件名判断文件是2003版本还是2007版本
if (isExcel2007(fileName)) {
isExcel2003 = false;
}
map = createExcel(mFile.getInputStream(), isExcel2003);
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
/**
* 根据excel里面的内容读取客户信息
* @param is 输入流
* @param isExcel2003 excel是2003还是2007版本
* @