# re: POI 如何得到 HSSFRow 的实际行高?  回复  更多评论
						  
					
					2009-10-22 11:12 by 
				
 
				我自己写的斌希望你能有收获 
happyyou2009@gmail.com
    public static float getExcelCellAutoHeight(String str, float fontCountInline) {
        float defaultRowHeight = 12.00f;
        float defaultCount = 0.00f;
        for (int i = 0; i < str.length(); i++) {
            float ff = getregex(str.substring(i, i + 1));
            defaultCount = defaultCount + ff;
        }
        return ((int) (defaultCount / fontCountInline) + 1) * defaultRowHeight;
    }
    public static float getregex(String charStr) {
        
        if(charStr==" ")
        {
            return 0.5f;
        }
        // 判断是否为字母或字符
        if (Pattern.compile("^[A-Za-z0-9]+$").matcher(charStr).matches()) {
            return 0.5f;
        }
        // 判断是否为全角
        if (Pattern.compile("[\u4e00-\u9fa5]+$").matcher(charStr).matches()) {
            return 1.00f;
        }
        Map<String, String> map = new HashMap<String, String>();
        map.put("#", "#");
        map.put("。", "。");
        map.put(",", ",");
        map.put("、", "、");
        map.put(";", ";");
        map.put("(", "(");
        map.put(")", ")");
        map.put("=", "=");
        map.put("-", "-");
        map.put(" ", " ");
        map.put("×", "×");
        map.put("&", "&");
        map.put("!", "!");
        map.put("《", "《");
        map.put("》", "》");
        map.put("“", "“");
        map.put("”", "”");
        map.put("?", "?");
        map.put("+", "+");
        map.put("【", "【");
        map.put("】", "】");
        map.put("{", "{");
        map.put("}", "}");
        if (map.containsKey(charStr)) {
            return 1.00f;
        }
        if (Pattern.compile("[^x00-xff]").matcher(charStr).matches()) {
            return 1.00f;
        }
        return 0.5f;
    }