Multiple cell styles cannot be applied to a single Cell
. The last cell style applied will overwrite any pre-existing cell style on the Cell
. Setting multiple CellStyle
s won't combined the set attributes of each style.
The solution is to create another CellStyle
that has the desired attributes of both of the other CellStyle
s. You can use the cloneStyleFrom
method to start with the attributes of one CellStyle
.
CellStyle combined = workbook.createCellStyle();
combined.cloneStyleFrom(colourCellStyle);
combined.setDataFormat(dateCellStyle.getDataFormat());
// You can copy other attributes to "combined" here if desired.
cell9.setCellStyle(combined);
This technique can be generalized to clone any existing cell style and copy individual attributes from a second existing cell style. As always, reuse any existing CellStyle
s, but if a different combination of attributes is required, then you must create and use a new CellStyle
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…