SpringMVC上传Excel数据文件.docxVIP

  • 2
  • 0
  • 约4.55千字
  • 约 4页
  • 2017-06-13 发布于北京
  • 举报
form id=fileUpload action=importOCRExcelData.do enctype=multipart/form-data method=postinput id=excelFile name=excelFile type=file /a href=javascript:void(0); title=点击下载模板 onclick=downloadModalExcel();点击下载模板/ainput type=button value=提交 class=quickpro-button onclick=submitExcel();//form/***数据文件导入**@paramrequest*@paramresponse*@throwsIOException*@throwsFileNotFoundException*/@RequestMapping({ importOCRExcelData })publicvoid 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**@paramworkbook*@paramsheetNum*@return*@throwsIOException*/publicstatic 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();for (int rowIx = minRowIx; rowIx = maxRowIx; rowIx++) { Row row = sheet.getRow(rowIx); StringBuilder sb = new StringBuilder();short minColIx = row.getFirstCellNum();short maxColIx = row.getLastCellNum();for (short colIx = minColIx; colIx = maxColIx; colIx++) { Cell cell = row.getCell(new Int

文档评论(0)

1亿VIP精品文档

相关文档