Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding border to a merged region in POI XSSF workbook

I'm using apache poi 3.7 and I need to put border to a range of cells or merged region.

how can I to apply border to a merged region when the sheet and workbook type is XSSF. In HSSF type I use RegionUtil-/HSSFRegionutil, but if use the first object (Regionutil) in XSSF type its doesn't works and puts a black background color to the range of cells.

Regionutil ussually works with CellRangeAddress and i don't find information about this trouble. I don't know if the CellRangeAddres causes this.

like image 276
Charlessmori Avatar asked Jun 30 '12 20:06

Charlessmori


1 Answers

@Jesanagua just saved my life, I just had to change a bit to match 3.17.

private void setBordersToMergedCells(HSSFSheet sheet) {
    int numMerged = sheet.getNumMergedRegions();
    for (int i = 0; i < numMerged; i++) {
        CellRangeAddress mergedRegions = sheet.getMergedRegion(i);
        RegionUtil.setBorderLeft(BorderStyle.THIN, mergedRegions, sheet);
        RegionUtil.setBorderRight(BorderStyle.THIN, mergedRegions, sheet);
        RegionUtil.setBorderTop(BorderStyle.THIN, mergedRegions, sheet);
        RegionUtil.setBorderBottom(BorderStyle.THIN, mergedRegions, sheet);

    }
}
like image 88
Marcos Almeida Avatar answered Sep 22 '22 09:09

Marcos Almeida