poi 如果给单个单元格加边框很好解决,可是合并单元格后如何加边框?
请各位大虾不吝赐教.

解决方案 »

  1.   

    把分给我吧。
        region = new Region(allLine - 2, (short) 6, allLine - 2, (short) 8);
        sheet.addMergedRegion(region);
        setRegion(region, wk.getCellStyle(CELLSTYLE_7_7_1_7_10_1_2), "節");
        public HSSFCellStyle getCellStyle(String key) {
            if (key == null) {
                return null;
            }        HSSFCellStyle cellStyle = (HSSFCellStyle) this.map.get(key);
            if (cellStyle == null) {
                cellStyle = this.createCellStyle();
                newCellStyle(cellStyle, key);
                this.map.put(key, cellStyle);
            }
            return cellStyle;
        }    private void newCellStyle(HSSFCellStyle cellStyle, String key) {        String[] params = key.split("_");
            cellStyle.setBorderLeft(new Integer(params[0]).shortValue());
            cellStyle.setBorderRight(new Integer(params[1]).shortValue());
            cellStyle.setBorderTop(new Integer(params[2]).shortValue());
            cellStyle.setBorderBottom(new Integer(params[3]).shortValue());
            if (!"0".equals(params[4])) {
                HSSFFont font = ZZExcelUtil.createFontA(this);
                font.setFontHeightInPoints(new Integer(params[4]).shortValue());
                cellStyle.setFont(font);
            }
            cellStyle.setVerticalAlignment(new Integer(params[5]).shortValue());
            cellStyle.setAlignment(new Integer(params[6]).shortValue());
        }