导入数据 org.apache.poi.hssf.usermodel.HSSFWorkbook

		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;
	}


 

你可能感兴趣的:(导入数据 org.apache.poi.hssf.usermodel.HSSFWorkbook)