//文件导入 public String printExcel() throws Exception { try { //获取路径 String dath = ServletActionContext.getServletContext().getRealPath("/tem"); //获取文件名字 File dathFile = new File(dath, fileFileName); //复制文件 FileUtils.copyFile(file, dathFile); //截取文件名字 fileFileName = fileFileName.substring(fileFileName.lastIndexOf("."), fileFileName.length()); //创建表格 Workbook workbook = null; if (fileFileName.toLowerCase().equals(".xls")) { workbook = new HSSFWorkbook(new FileInputStream(dathFile)); } else if (fileFileName.toLowerCase().equals(".xlsx")) { workbook = new XSSFWorkbook(new FileInputStream(dathFile)); } //记录有几条记录没有添加成功 int count = 0; //成功数据 int c = 0; //记录重复业务单号 StringBuffer sb = new StringBuffer(); //取出多少条记录 int sheetCount = workbook.getNumberOfSheets(); //保存错误日志 List<PolicyRemain> errorList = new ArrayList<PolicyRemain>(); for (int i = 0; i < sheetCount; i++) { Sheet sheet = workbook.getSheetAt(i); if (sheet == null) { continue; } int rowCount = sheet.getLastRowNum() + 1; for (int j = 1; j < rowCount; j++) { Row row = sheet.getRow(j); if (row == null) { continue; } //根据该变量判断该记录是否需要保存到错误集合中 int error = 0; //创建对象 PolicyRemain policyRemain = new PolicyRemain(); try { //订单号 String orderNo = UtilDate.getRemainOrderNo(); policyRemain.setOrderNo(orderNo); Cell cell = row.getCell(0); if (cell == null || StringUtils.isBlank(cell.toString())) { continue; } if (String.valueOf(cell).lastIndexOf(".") == -1) { policyRemain.setBusinessOrderNo(cell == null ? null : String.valueOf(cell));//业务单号 } else { policyRemain.setBusinessOrderNo(cell == null ? null : String.valueOf(cell).substring(0, String.valueO
poi导入
最新推荐文章于 2024-04-24 13:17:14 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)