We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Eclipse how to set a outline border on a merged cell?

Hi,

I am using aspose for Java on Eclipse. I am able to merge a set of cells by the generic code:

Workbook workbook = new Workbook();

Worksheets worksheets = workbook.getWorksheets();

Worksheet worksheet = worksheets.getSheet(0);

Cells cells = worksheet.getCells();

cells.merge(row, col, mergeRow, mergeCol);

But now how would I go about and add a preset outline around the merged cell?

I have tried :

this.setStyle_addBorder(cell, BorderType.TOP, BorderLineType.THIN);

this.setStyle_addBorder(cell, BorderType.BOTTOM, BorderLineType.THIN);

this.setStyle_addBorder(cell, BorderType.LEFT, BorderLineType.THIN);

this.setStyle_addBorder(cell, BorderType.RIGHT, BorderLineType.THIN);

Which can only give me exact results per cell but I need it a little cleaner.

I cannot use cells.createRange() as it does not seem to exist. There is however one called:

NamedRange range = cells.createNamedRange("Notes", row, col, numRow, numCol);

range.setOutlineBorder(BorderLineType.THIN, Color.BLACK);

Except it does not work when tested. Any advice?

Thank you

Hi,

Thanks for your posting and using Aspose.Cells.

Please download and use the latest version: Aspose.Cells for Java 8.0.1 it works fine.

I was able to set outline borders of the merged cells successfully. Please see the following code. I have attached the output xlsx file generated by it for your reference.

Java


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.getWorksheets().get(0);


Range range = worksheet.getCells().createRange(“B2:D4”);


range.merge();


range.setOutlineBorder(BorderType.LEFT_BORDER, CellBorderType.THICK, Color.getGreen());

range.setOutlineBorder(BorderType.RIGHT_BORDER, CellBorderType.THICK, Color.getGreen());

range.setOutlineBorder(BorderType.TOP_BORDER, CellBorderType.THICK, Color.getGreen());

range.setOutlineBorder(BorderType.BOTTOM_BORDER, CellBorderType.THICK, Color.getGreen());


workbook.save(“output.xlsx”);