Javaのpoi技術はExcelを遍歴する時に空のCellを行って、空のrow、判断します 4398 ワード Apache POI poi エクセル /** * */ @Override public List add(HttpServletRequest request) { // TODO Auto-generated method stub List num=new ArrayList(); MultipartHttpServletRequest multipartRequest =(MultipartHttpServletRequest) request; CommonsMultipartFile file = (CommonsMultipartFile)multipartRequest.getFile("zlUpload"); if(file!=null){ try { num = save(file.getInputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } returnnum; } /** * Excel */ private List save(InputStream inputStream) throwsIOException { // TODO Auto-generated method stub List error_num = new ArrayList(); List temp =(List)readXls(inputStream,error_num); System.out.println(temp.get(0).getClass().getName()); if(temp.get(0).getClass().getName().equals("org.apache.poi.hssf.usermodel.HSSFCell")){ return error_num; }else{ TStudentNo student = null; List studentList = newArrayList(); for(int i=0;ierror_num) throws IOException { InputStream is = new BufferedInputStream(inputStream); HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is); TStudentNo student = null; List list = new ArrayList(); // Sheet for(int numSheet =0;numSheet temp = new ArrayList(); temp.add(0, name); temp.add(1, student_no); temp.add(2, phone); temp.add(3, class_no); temp.add(4, subject_category); int temp1 = 0;// for for(int i=0;i<5;i++){ // temp1 = CheckRowError(temp.get(i),error_num,rowNum,i); if(temp1==-1){ break; } } if(temp1==-1){ return temp; } student.setName(getCellValue(name)); student.setPhone(getCellValue(phone)); student.setStudent_no(getCellValue(student_no)); student.setClass_no(getCellValue(class_no)); student.setSubject_category(Integer.parseInt(getCellValue(subject_category))); list.add(student); }else{ continue; } } } return list; } /** * Excel */ private String getCellValue(HSSFCell cell) { String cellValue = ""; DecimalFormat df = newDecimalFormat("#"); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: cellValue =cell.getRichStringCellValue().getString().trim(); break; case HSSFCell.CELL_TYPE_NUMERIC: cellValue =df.format(cell.getNumericCellValue()).toString(); break; case HSSFCell.CELL_TYPE_BOOLEAN: cellValue =String.valueOf(cell.getBooleanCellValue()).trim(); break; case HSSFCell.CELL_TYPE_FORMULA: cellValue =cell.getCellFormula(); break; default: cellValue = ""; } return cellValue; } // private int CheckRowError(HSSFCell cell,Listerror_num,int rowNum,int cell_num){ // if(cell==null||cell.equals("")||cell.getCellType() ==HSSFCell.CELL_TYPE_BLANK){ error_num.add(" ! "+(rowNum+1)+" "+(cell_num+1)+" 。"+" , , !"); return -1; } return 0; } // private int CheckRowNull(HSSFRow hssfRow){ int num = 0; Iterator cellItr =hssfRow.iterator(); while(cellItr.hasNext()){ Cell c =cellItr.next(); if(c.getCellType() ==HSSFCell.CELL_TYPE_BLANK){ num++; } } return num; } JSP EL式学習ノート CentOS7でMySQL/MariaDBのプロセスが落ちる対策