多个单元格样式不能应用于单个
Cell。应用的最后一个单元格样式将覆盖上任何现有的单元格样式
Cell。设置多个
CellStyle不会合并每种样式的设置属性。
解决方案是创建一个
CellStyle具有其他两个属性的属性
CellStyle。您可以使用该
cloneStyleFrom方法以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);
可以普遍使用此技术来克隆任何现有单元格样式并从第二种现有单元格样式复制单个属性。与往常一样,重用任何现有
CellStyle,但是如果需要不同的属性组合,则必须创建并使用new
CellStyle。



