文档详情

SpringMVC 上传Excel 数据文件.docx

发布:2017-07-08约字共4页下载文档
文本预览下载声明
form id=fileUpload action=importOCRExcelData.do enctype=multipart/form-data method=post input id=excelFile name=excelFile type=file / a href=javascript:void(0); title=点击下载模板 onclick=downloadModalExcel();点击下载模板/a input type=button value=提交 class=quickpro-button onclick=submitExcel();/ /form /** * 数据文件导入 * * @param request * @param response * @throws IOException * @throws FileNotFoundException */ @RequestMapping({ importOCRExcelData }) public void importOCRExcelData(HttpServletRequest request,HttpServletResponse response) throws FileNotFoundException, IOException { MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request; MultipartFile file = mulRequest.getFile(excelFile); String filename = file.getOriginalFilename(); if (filename == null || .equals(filename)) { } try { InputStream input = file.getInputStream(); XSSFWorkbook workBook = new XSSFWorkbook(input); ListString sfList = ExportHelper.exportListFromExcel(workBook, 0); for(int i=0 ; isfList.size();i++) { LOGGER.info(【+sfList.get(i).toString()+】 ); } } catch (Exception e) { LOGGER.error(e); } } /** * 由指定的Sheet导出至List * * @param workbook * @param sheetNum * @return * @throws IOException */ public static ListString exportListFromExcel(Workbook workbook, int sheetNum) { Sheet sheet = workbook.getSheetAt(sheetNum); // 解析公式结果 FormulaEvaluator evaluator = workbook.getCreationHelper() .createFormulaEvaluator(); ListString list = new ArrayListString(); int minRowIx = sheet.getFirstRowNum(); int maxRowIx = sheet.getLastRowNum();
显示全部
相似文档