当前位置:网站首页>Easypoi之excel多sheet导入
Easypoi之excel多sheet导入
2022-07-17 05:08:00 【qq_42042158】
多sheet导入跟简单导入差不多,只是controller层略微有点差别
其他代码点击Easypoi之excel简单导入
controller层代码
/** * 多sheet导入Excel数据 */
@RequestMapping(value = "multImports",method = RequestMethod.POST)
@ResponseBody
public String multImports(MultipartFile file) throws IOException {
if (null==file){
return GetResult.getResultObj("文件上传失败");
}
//根据file得到Workbook,主要是要根据这个对象获取,传过来的excel有几个sheet页
Workbook hssfWorkbook = getWorkBook(file);
//获取sheet数量
int sheetNum = hssfWorkbook.getNumberOfSheets();
ImportParams params = new ImportParams();
//表头在第几行
params.setTitleRows(5);
try {
List<Applys> list = new ArrayList<>();
for (int sheetIndex = 0; sheetIndex < sheetNum; sheetIndex++) {
//第几个sheet页
params.setStartSheetIndex(sheetIndex);
List<Applys> result = ExcelImportUtil.importExcel(file.getInputStream(), Applys.class, params);
list.addAll(result);
}
for (int i = 0; i < list.size(); i++) {
if (null==list.get(i).getRealName()){
list.remove(i);
i--;
}
}
if (list.size()==0){
return GetResult.getResultObj("数据读取失败,检查Excel数据格式");
}
if (ApplyService.saveBatch(list)){
return GetResult.getResultObj("ok");
}
} catch (Exception e) {
e.printStackTrace();
}
return GetResult.getResultObj("文件读取失败");
}
/** * 获取Excel中的sheet * @param file * @return * @throws IOException */
public static Workbook getWorkBook(MultipartFile file) throws IOException {
//这样写excel能兼容03和07
InputStream is = file.getInputStream();
Workbook hssfWorkbook = null;
try {
hssfWorkbook = new HSSFWorkbook(is);
} catch (Exception ex) {
is =file.getInputStream();
hssfWorkbook = new XSSFWorkbook(is);
}
return hssfWorkbook;
}
边栏推荐
- STL container -- basic operation of map
- Uni app conditional compilation ifdef ENDIF compatible with multiple terminals
- 微信小程序状态栏
- Multifunctional (Implementation) encapsulation function
- Internship project 1 - personalized homepage configuration
- Travel data acquisition, data analysis and data mining [2022.5.30]
- BUUCTF 杂项——二维码
- cookie是否有效时间限定?如何设置cookie?手把手教你设置
- 遍历的方法总结
- 小程序云开发 上传图片到云存储
猜你喜欢

【C语言—零基础第六课】输入输出语句格式与复合语句

微信小程序5-基础加强(没写完)

645. 错误的集合

Submit the uniapp form (input, radio, picker) to get the parameter value

微信小程序 学习笔记

实习项目3-更改所有者

uniapp中使用ucharts图表,饼状图,柱状图,折线图

【C语言_复习_学习第二课】什么是进制?进制之间应该如何转换

使用Echars实现水滴状、环形图、分割图、堆叠、组织架构图、地图轮廓等图表

Internship project 1 - personalized homepage configuration
随机推荐
【C语言—零基础第十四课】变量的作用域与存储类
交换机用户模式、特权模式、全局模式、端口模式
Submit the uniapp form (input, radio, picker) to get the parameter value
Cesium 绑定鼠标事件和移除鼠标事件
微信小程序5-基础加强(没写完)
无重复字符的最长字串
学习C语言的第五天
Cesium 获取鼠标点击处经纬度的三种方法
这么6的刷题网站你不会没听说过吧?你已经out 了?
滚动轮加载的两种js方法及模态框拖拽归总
ArcMap 创建常量栅格并镶嵌至新栅格
MySQL optimization
B域,M域,O域具体是指什么
Internship project 2 - Homepage configuration - my data module
Baidu map realizes thermal map
使用js实现安居客二级菜单及(注意事项和问题点演示)完整版
Leetcode53. maximum subarray and
父组件加scoped有时也会影响子组件
轮播图移动速度(匀速,缓动)案例归总
(elaborate) ES6 remaining parameters, ES6 built-in objects, template string content (detailed example Dictionary) and practical cases of flexible use of the project