1 回答

TA貢獻1802條經(jīng)驗 獲得超4個贊
public static List<Object> test(FileItem fileInput, String sheetName) {
List<Object> list = null;
if (null == fileInput) {
throw new ServiceException("導(dǎo)入文件為空");
}
Workbook wb = null;
InputStream is = null;
Sheet sheet = null;
try {
is = fileInput.getInputStream();
wb = new XSSFWorkbook(is);
sheet = wb.getSheet(sheetName);
} catch (Exception e) {
throw new ServiceException("上傳excel版本文件解析失敗");
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
if (sheet != null) {
// 初始化Excel欄目
List<CellMapping> mappingList = InfrastrUtil.getModColumns(null);
try {
list = ExcelUtils.excel2bean(sheet, InfrastrVo.class, mappingList);
} catch (Exception e) {
throw new ServiceException(ErrorCode.Upload_File_Error, "Excel解析失敗");
}
} else {
throw new ServiceException(ErrorCode.Upload_File_Error, "未找到模板對應(yīng)sheet");
}
return list;
}
添加回答
舉報