猿问

java用poi操作excel的时候,new XSSFWorkbook,总是报错?

https://img2.mukewang.com/5cbe84dc0001213003860078.jpg

走到箭头那一步的时候,总是调到handlerMehtodInvoker.class 这里
为什么捕捉不到异常?

https://img1.mukewang.com/5cbe84db0001d94704400127.jpg


杨魅力
浏览 2246回答 1
1回答

12345678_0001

看你的代码,貌似实现的是要读取Excel文件吧。代码如下:具体的跟你的POI所支持的EXCEL版本有关系的。public List<RackVo> importExcel(@File("upload")FileItem fileInput, ErrorContext error) {List<RackVo> list = null;&nbsp; &nbsp; if (null == fileInput) {&nbsp; &nbsp; &nbsp; &nbsp; throw new ServiceException(ErrorCode.Params_Lost, "机柜导入文件");&nbsp; &nbsp; }&nbsp; &nbsp; Workbook wb = null;&nbsp; &nbsp; InputStream is = null;&nbsp; &nbsp; Sheet sheet = null;&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; is = fileInput.getInputStream();&nbsp; &nbsp; &nbsp; &nbsp; wb = new XSSFWorkbook(is);&nbsp; &nbsp; &nbsp; &nbsp; sheet = wb.getSheet(sheetName);&nbsp; &nbsp; } catch (Exception e) {&nbsp; &nbsp; &nbsp; &nbsp; throw new ServiceException(ErrorCode.Upload_File_Error, "上传excel版本文件解析失败");&nbsp; &nbsp; } finally {&nbsp; &nbsp; &nbsp; &nbsp; if (is != null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (IOException e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; if (sheet != null) {&nbsp; &nbsp; &nbsp; &nbsp; // 初始化Excel栏目&nbsp; &nbsp; &nbsp; &nbsp; List<CellMapping> mappingList = RackUtil.getModColumns(null);&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list = ExcelUtils.excel2bean(sheet, RackVo.class, mappingList);&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new ServiceException(ErrorCode.Upload_File_Error, "Excel解析失败");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; throw new ServiceException(ErrorCode.Upload_File_Error, "未找到模板对应sheet");&nbsp; &nbsp; }&nbsp; &nbsp; return list;}
随时随地看视频慕课网APP

相关分类

Java
我要回答