* @param sheet sheet to set background color
* @param rect selection range
* @param color color to use
*/
public static void setBackgroundColor(Worksheet sheet, Rect rect, String color) {
final Book book = (Book) sheet.getWorkbook();
final Color bsColor = BookHelper.HTMLToColor(book, color);
for (int row = rect.getTop(); row <= rect.getBottom(); row++)
for (int col = rect.getLeft(); col <= rect.getRight(); col++) {
Cell cell = Utils.getOrCreateCell(sheet, row, col);
CellStyle cs = cell.getCellStyle();
final Color srcColor = cs.getFillForegroundColorColor();
if (Objects.equals(srcColor, bsColor)) {
continue;
}
CellStyle newCellStyle = book.createCellStyle();
newCellStyle.cloneStyleFrom(cs);
//bug#ZSS-34: cell background color does not show in excel
//20110819, henrichen@zkoss.org: set color to a cell shall change its fillPattern to "solid" automatically
final short patternType = cs.getFillPattern();