ExcelUtils 工具类 导入

本文介绍了一个初级版本的ExcelUtils工具类,用于Excel的导入功能。文中详细阐述了使用步骤,包括引入库、调用导入方法以及工具类的使用。虽然目前仅支持导入,但作者计划后续添加导出功能,以实现更全面的Excel操作。
摘要由CSDN通过智能技术生成

包含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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值