Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liaochong committed Nov 16, 2019
1 parent 7f87471 commit 21b42e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.liaochong</groupId>
<artifactId>myexcel</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<packaging>jar</packaging>

<name>myexcel</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.awt.*;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -96,33 +95,29 @@ public static void setFont(Supplier<Font> fontSupplier, CellStyle cellStyle, Map
}
String fontColor = tdStyle.get(FONT_COLOR);
if (StringUtil.isNotBlank(fontColor)) {
font = setFontColor(fontSupplier, customColor, fontColor);
font = createFontIfNull(fontSupplier, font);
font = setFontColor(font, customColor, fontColor);
}
if (font != null) {
cellStyle.setFont(font);
fontMap.put(cacheKey, font);
}
}

private static Font setFontColor(Supplier<Font> fontSupplier, CustomColor customColor, String fontColor) {
private static Font setFontColor(Font font, CustomColor customColor, String fontColor) {
Short colorPredefined = ColorUtil.getPredefinedColorIndex(fontColor);
if (Objects.nonNull(colorPredefined)) {
Font font = fontSupplier.get();
font = createFontIfNull(fontSupplier, font);
if (colorPredefined != null) {
font.setColor(colorPredefined);
return font;
}
int[] rgb = ColorUtil.getRGBByColor(fontColor);
if (Objects.isNull(rgb)) {
if (rgb == null) {
return null;
}
Font font = null;
if (customColor.isXls()) {
short index = ColorUtil.getCustomColorIndex(customColor, rgb);
font = createFontIfNull(fontSupplier, font);
font.setColor(index);
} else {
font = createFontIfNull(fontSupplier, font);
((XSSFFont) font).setColor(new XSSFColor(new Color(rgb[0], rgb[1], rgb[2]), customColor.getDefaultIndexedColorMap()));
}
return font;
Expand Down

0 comments on commit 21b42e3

Please sign in to comment.