<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一條老狗

               老狗拉破車
    posts - 12, comments - 11, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    POI 如何得到 HSSFRow 的實際行高?

    Posted on 2007-07-27 14:22 一條老狗 閱讀(4100) 評論(2)  編輯  收藏 所屬分類: Java

    以下是官方的一個例子:

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s 
    = wb.createSheet();
        HSSFRow r 
    = null;
        HSSFCell c 
    = null;
        HSSFCellStyle cs 
    = wb.createCellStyle();
        HSSFFont f 
    = wb.createFont();
        HSSFFont f2 
    = wb.createFont();

        cs 
    = wb.createCellStyle();

        cs.setFont( f2 );
        
    //Word Wrap MUST be turned on
        cs.setWrapText( true );

        r 
    = s.createRow( (short2 );
        r.setHeight( (
    short0x349 );
        c 
    = r.createCell( (short2 );
        c.setCellType( HSSFCell.CELL_TYPE_STRING );
        c.setCellValue( 
    "Use \n with word wrap on to create a new line" );
        c.setCellStyle( cs );
        s.setColumnWidth( (
    short2, (short) ( ( 50 * 8 ) / ( (double1 / 20 ) ) );

        FileOutputStream fileOut 
    = new FileOutputStream( "workbook.xls" );
        wb.write( fileOut );
        fileOut.close();

     

    這里它是使用 r.setHeight((short)0x349) 寫死了行高的,如何根據實際內容自動計算出其行高呢?
    我們可以不設置其行高,此時Excel能夠正確顯示出來,但看上去太擠,不好看。
    我是希望在文字需要占的實際行高基礎上再加上一些空白,這樣才好看。
    但此時調用 r.getHeight() 取不到值。

    我想這個需求可能是實現不了了。

     


    評論

    # re: POI 如何得到 HSSFRow 的實際行高?[未登錄]  回復  更多評論   

    2009-06-18 13:16 by HI
    重新打開后,能取到.

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

    }


    主站蜘蛛池模板: 亚洲日产韩国一二三四区| 亚洲国产成人久久精品99 | 一级毛片免费播放试看60分钟| 成年丰满熟妇午夜免费视频| 中文字幕 亚洲 有码 在线 | 亚洲一区二区无码偷拍| 毛片免费在线视频| 亚洲爆乳无码专区www| 国产又大又长又粗又硬的免费视频| 亚洲AV无码成人精品区日韩| 思思99re66在线精品免费观看| 亚洲乱码中文字幕在线| 亚洲va中文字幕无码| 两个人看的www免费视频中文| 亚洲AV无码一区东京热| 免费在线观看视频网站| 亚洲色大成WWW亚洲女子| 免费大片黄手机在线观看| 中文字幕看片在线a免费| 亚洲精品福利视频| 成人午夜18免费看| 日本激情猛烈在线看免费观看| 亚洲无码在线播放| 久热中文字幕在线精品免费| 亚洲人成人伊人成综合网无码| 免费一级毛片在级播放| 叮咚影视在线观看免费完整版| 久久丫精品国产亚洲av不卡 | 亚洲依依成人亚洲社区| 亚洲美日韩Av中文字幕无码久久久妻妇| 四虎精品免费永久免费视频| 日本亚洲欧洲免费天堂午夜看片女人员 | 亚洲国产AV无码专区亚洲AV| 1000部免费啪啪十八未年禁止观看 | 亚洲专区一路线二| 免费h黄肉动漫在线观看| 最近免费mv在线观看动漫| 亚洲国产成a人v在线观看 | 中文字幕亚洲第一| 免费99精品国产自在现线| 国产免费MV大全视频网站|