How to assign border to cellrangeAddress with apache poi?

0

One question, I am using apache poi and I would like to know if anyone here knows how to apply a border style to a cellrangeaddress, I am using apache poi 3.14.

I really have little using this tool, what I have done is:

-assign in the cellstyle the border style styleCT.setBorderBottom (CellStyle.BORDER_MEDIUM);

-I believe the cellrangeaddress and assigned that style.

header = row.createCell (5); sheet.addMergedRegion (new CellRangeAddress (20,20,5,6));             header.setCellValue (pesogm2);             header.setCellStyle (styleCT);

but only the first cell takes it.

Does anyone know how I could do to take the whole set of cells?

Thank you in advance for your help.

    
asked by Jesus Martinez 21.02.2018 в 01:56
source

1 answer

1

I've attached the methods I did to make merge and add borde :

protected void setMerge(Sheet sheet, int numRow, int untilRow, int numCol, int untilCol) {
    CellRangeAddress cellMerge = new CellRangeAddress(numRow, untilRow, numCol, untilCol);
    sheet.addMergedRegion(cellMerge);
    setBordersToMergedCells(sheet, cellMerge);
}

Assign the border:

protected void setBordersToMergedCells(Sheet sheet, CellRangeAddress rangeAddress) {
    RegionUtil.setBorderTop(BorderStyle.MEDIUM, rangeAddress, sheet);
    RegionUtil.setBorderLeft(BorderStyle.MEDIUM, rangeAddress, sheet);
    RegionUtil.setBorderRight(BorderStyle.MEDIUM, rangeAddress, sheet);
    RegionUtil.setBorderBottom(BorderStyle.MEDIUM, rangeAddress, sheet);
}

There is also another one where you can send the type of border you need in merge .

    protected void setBordersToMergedCells(Sheet sheet, CellRangeAddress rangeAddress, BorderStyle typeBorder) {
    RegionUtil.setBorderTop(typeBorder, rangeAddress, sheet);
    RegionUtil.setBorderLeft(typeBorder, rangeAddress, sheet);
    RegionUtil.setBorderRight(typeBorder, rangeAddress, sheet);
    RegionUtil.setBorderBottom(typeBorder, rangeAddress, sheet);
}
    
answered by 21.09.2018 в 21:06