Hello,
I would like to set the border colour for selected cells unfortunately, this solution does not work without setting the property
cell.getCellFormat().getBorders().setLineWidth(...)
code presents bug:
documentBuilder.startTable();
final Cell[][] tableCells = new Cell[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
tableCells[i][j] = documentBuilder.insertCell();
}
documentBuilder.endRow();
}
final Color red = new Color(255, 0, 0);
final CellFormat cellFormat = tableCells[1][1].getCellFormat();
/* Set red borders color only for one cell */
final BorderCollection borders = cellFormat.getBorders();
borders.getLeft().setColor(red);
borders.getRight().setColor(red);
borders.getBottom().setColor(red);
borders.getTop().setColor(red);
final Color blue = new Color(68, 114, 196);
tableCells[1][2].getCellFormat().getBorders().getRight().setColor(blue);
/* With set line width works ... */
tableCells[2][2].getCellFormat().getBorders().setLineWidth(2D);
tableCells[2][2].getCellFormat().getBorders().setColor(blue);
documentBuilder.endTable();
saveDocument(documentBuilder);
protected void saveDocument(DocumentBuilder documentBuilder) {
DateFormat dateFormat = new SimpleDateFormat("_HH_mm_ss");
Date currentDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
final String outPath = System.getProperty("user.dir") + File.separator + "table_test_word" + dateFormat.format(currentDate) + ".docx";
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
try {
documentBuilder.getDocument().save(outPath, options);
} catch (Exception e) {
fail("Test failed during save due to: " + e.getMessage());
e.printStackTrace();
}
}