2016-09-29 79 views
4

我使用Apache POI 3.15。 我最近切換到最新版本,我們現在有一些不推薦的方法,'短'邊框樣式,'短'對齊... 對於這些不推薦使用的方法,我們有新的方法與枚舉參數(如BorderStyle,Horizo​​ntalAlignment,FillPatternType .. )。 對我來說沒問題。Apache POI 3.15:RegionUtil和BorderStyle?

現在,我還使用RegionUtil爲合併區域添加一些樣式。 但是RegionUtil似乎使用舊的'短'風格。

這裏我的代碼(從https://stackoverflow.com/a/23619827/502040但沒有使用過時的方法啓發):

protected static void addMergedRegion(Sheet sheet, int iRowMin, int iRowMax, int iColMin, int iColMax) { 
    CellRangeAddress cellZone = new CellRangeAddress(iRowMin, iRowMax, iColMin, iColMax); 
    sheet.addMergedRegion(cellZone); 

    Cell cell = sheet.getRow(iRowMin).getCell(iColMin); 
    if (cell != null) { 
     RegionUtil.setBorderBottom(cell.getCellStyle().getBorderBottomEnum().getCode(), cellZone, sheet); 
     RegionUtil.setBorderTop(cell.getCellStyle().getBorderTopEnum().getCode(), cellZone, sheet); 
     RegionUtil.setBorderLeft(cell.getCellStyle().getBorderLeftEnum().getCode(), cellZone, sheet); 
     RegionUtil.setBorderRight(cell.getCellStyle().getBorderRightEnum().getCode(), cellZone, sheet); 

     RegionUtil.setBottomBorderColor(cell.getCellStyle().getBottomBorderColor(), cellZone, sheet); 
     RegionUtil.setTopBorderColor(cell.getCellStyle().getTopBorderColor(), cellZone, sheet); 
     RegionUtil.setLeftBorderColor(cell.getCellStyle().getLeftBorderColor(), cellZone, sheet); 
     RegionUtil.setRightBorderColor(cell.getCellStyle().getRightBorderColor(), cellZone, sheet); 
    } 
} 

但我在日誌中發現了一些線,如:

邊框簡短的用法

我在CellUtil類中找到了此行的來源:

private static BorderStyle getBorderStyle(Map<String, Object> properties, String name) { 
    Object value = properties.get(name); 
    BorderStyle border; 
    if (value instanceof BorderStyle) { 
     border = (BorderStyle) value; 
    } 
    // @deprecated 3.15 beta 2. getBorderStyle will only work on BorderStyle enums instead of codes in the future. 
    else if (value instanceof Short) { 
     if (log.check(POILogger.WARN)) { 
      log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map uses Short values for " 
        + name + ". Should use BorderStyle enums instead."); 
     } 
     System.out.println("BorderStyle short usage"); 
     short code = ((Short) value).shortValue(); 
     border = BorderStyle.valueOf(code); 
    } 
    else if (value == null) { 
     border = BorderStyle.NONE; 
    } 
    else { 
     throw new RuntimeException("Unexpected border style class. Must be BorderStyle or Short (deprecated)."); 
    } 
    return border; 
} 

你有解決方案使用Enum樣式爲合併區域製作一些邊框嗎?

+2

我建議在POI Bugzilla中打開一個bug,希望Javen(POI enum guru)可以修復'RegionUtil'! – Gagravarr

+0

我在那裏提交bugzilla應用程序中的錯誤。鏈接在這裏:https://bz.apache.org/bugzilla/show_bug.cgi?id=60187 –

回答

3

你需要使用Apache POI的新版本比3.15,這是唯一的固定在r1762856

您需要Apache POI 3.16 Beta 1版本或更高版本,或者現在每晚/ SVN主幹/ git的頭版本所做的20160930

+0

我有同樣的問題,我試過3.16beta1和3.16beta2。但它不適合我。 –