包含excel 导入 导出 初级版本,并没有什么高深的合并之类的
前言
不想在天天百度类似的东西了,资料整理,早不知道抄谁的了
二、使用步骤
1.引入库
代码如下(示例):
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest;
2.excel导入调用
代码如下(示例):
public void importFile(HttpServletRequest request, Integer moduleId, Integer moduleType,HttpServletResponse response){
String[] title={"标题","年度","日期"};
String[] column={"title","year","time"};
try{
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("file");
// 这个是用来记录错误信息的,返回页面使用
Map<String, String> errorMsg = new HashMap<String, String>();
// 必填项验证
Map<String, String> requiredInfo= new HashMap<String, String>();
requiredInfo.put("1","必填");// key:第几列 value:返回页面使用
LogBean logBean = new LogBean();// 这个可以忽略,只是为了提醒大家,第四个参数是 实体的class 文件
List<LogBean> excelDataList = ExcelUtils.readExcel(file, title, column, LogBean.class, equiredInfo, errorMsg, false);
if(excelDataList!=null){
//可以操作了
}
}catch(Exception e){
e.printStackTrace();
}
}
3.excel工具类
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.