데이터 가져오기 org.apache.poi.hssf.usermodel.HSSFWorkbook

2226 단어
		HSSFWorkbook book = null;
		try {
			book = new HSSFWorkbook(file.getInputStream());
		} catch (IOException e) {
			log.error(" , excel !",e);
			return 1;
		}
		
		HSSFSheet sheet = book.getSheetAt(0);
		int lastRowNum = sheet.getLastRowNum();
		log.info("sheet name:"+ sheet.getSheetName()+", lastRowNum:"+lastRowNum);
		
		if(lastRowNum < 1){
			return 2;
		}
		
		String username = UserSession.getUser().getUserName();
		List disableCustomerList = new LinkedList();
		
		for(int i=1;i

 

	/**
	 *  ( String , 100 )
	 * @param cell
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static String getCellValue(Cell cell) {
		String value;
		if(cell == null) return "";
		switch (cell.getCellType()) {
		    case Cell.CELL_TYPE_NUMERIC:	//   
		    	if(HSSFDateUtil.isCellDateFormatted(cell)){// 
		    		 Date d = cell.getDateCellValue();
		    		 DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
		    		 value = formater.format(d);
		    	}else{
		    		value = new DecimalFormat("#").format(cell.getNumericCellValue());
		    	}
		        break;  
		    case Cell.CELL_TYPE_STRING:		//   
		    	value = cell.getStringCellValue().trim();
		        break;  
		    case Cell.CELL_TYPE_BOOLEAN:	//Boolean  
		        value = String.valueOf(cell.getBooleanCellValue());
		        break;  
		    case Cell.CELL_TYPE_FORMULA:	//   
		        value = cell.getCellFormula();
		        break;  
		    case Cell.CELL_TYPE_BLANK:	//   
		    	value = "";
		        break;  
		    case Cell.CELL_TYPE_ERROR:	//   
		    	value = "";
		        break;  
		    default:  
		    	value = "";
		        break;  
		}
		return value;
	}

좋은 웹페이지 즐겨찾기