|
@@ -1,7 +1,6 @@
|
|
|
package com.anjiplus.template.gaea.business.modules.reportexcel.util;
|
|
|
|
|
|
|
|
|
-
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFPalette;
|
|
@@ -15,6 +14,7 @@ import org.apache.poi.xssf.usermodel.XSSFColor;
|
|
|
|
|
|
/**
|
|
|
* 来自:https://github.com/mengshukeji/LuckysheetServer
|
|
|
+ *
|
|
|
* @author Administrator
|
|
|
*/
|
|
|
@Slf4j
|
|
@@ -22,22 +22,22 @@ public class ColorUtil {
|
|
|
|
|
|
private static final String S = "0123456789ABCDEF";
|
|
|
|
|
|
- public static Short getColorByStr(String colorStr){
|
|
|
+ public static Short getColorByStr(String colorStr) {
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
HSSFPalette palette = workbook.getCustomPalette();
|
|
|
|
|
|
- if(colorStr.toLowerCase().startsWith("rgb")){
|
|
|
- colorStr=colorStr.toLowerCase().replace("rgb(","").replace(")","");
|
|
|
- String[] colors=colorStr.split(",");
|
|
|
- if(colors.length==3){
|
|
|
- try{
|
|
|
- int red = Integer.parseInt(colors[0].trim(),16);
|
|
|
- int green = Integer.parseInt(colors[1].trim(),16);
|
|
|
- int blue = Integer.parseInt(colors[2].trim(),16);
|
|
|
+ if (colorStr.toLowerCase().startsWith("rgb")) {
|
|
|
+ colorStr = colorStr.toLowerCase().replace("rgb(", "").replace(")", "");
|
|
|
+ String[] colors = colorStr.split(",");
|
|
|
+ if (colors.length == 3) {
|
|
|
+ try {
|
|
|
+ int red = Integer.parseInt(colors[0].trim(), 16);
|
|
|
+ int green = Integer.parseInt(colors[1].trim(), 16);
|
|
|
+ int blue = Integer.parseInt(colors[2].trim(), 16);
|
|
|
|
|
|
- HSSFColor hssfColor=palette.findSimilarColor(red,green,blue);
|
|
|
+ HSSFColor hssfColor = palette.findSimilarColor(red, green, blue);
|
|
|
return hssfColor.getIndex();
|
|
|
- }catch (Exception ex){
|
|
|
+ } catch (Exception ex) {
|
|
|
log.error(ex.toString());
|
|
|
return null;
|
|
|
}
|
|
@@ -45,27 +45,27 @@ public class ColorUtil {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- if(colorStr.equals("#000")){
|
|
|
- colorStr="#000000";
|
|
|
+ if (colorStr.equals("#000")) {
|
|
|
+ colorStr = "#000000";
|
|
|
}
|
|
|
- if(colorStr!=null && colorStr.length()>=6){
|
|
|
- try{
|
|
|
- if(colorStr.length()==8){
|
|
|
- colorStr=colorStr.substring(2);
|
|
|
+ if (colorStr != null && colorStr.length() >= 6) {
|
|
|
+ try {
|
|
|
+ if (colorStr.length() == 8) {
|
|
|
+ colorStr = colorStr.substring(2);
|
|
|
}
|
|
|
- if(colorStr.length()==7){
|
|
|
- colorStr=colorStr.substring(1);
|
|
|
+ if (colorStr.length() == 7) {
|
|
|
+ colorStr = colorStr.substring(1);
|
|
|
}
|
|
|
- String str2 = colorStr.substring(0,2);
|
|
|
- String str3 = colorStr.substring(2,4);
|
|
|
- String str4 = colorStr.substring(4,6);
|
|
|
- int red = Integer.parseInt(str2,16);
|
|
|
- int green = Integer.parseInt(str3,16);
|
|
|
- int blue = Integer.parseInt(str4,16);
|
|
|
+ String str2 = colorStr.substring(0, 2);
|
|
|
+ String str3 = colorStr.substring(2, 4);
|
|
|
+ String str4 = colorStr.substring(4, 6);
|
|
|
+ int red = Integer.parseInt(str2, 16);
|
|
|
+ int green = Integer.parseInt(str3, 16);
|
|
|
+ int blue = Integer.parseInt(str4, 16);
|
|
|
|
|
|
- HSSFColor hssfColor=palette.findSimilarColor(red,green,blue);
|
|
|
+ HSSFColor hssfColor = palette.findSimilarColor(red, green, blue);
|
|
|
return hssfColor.getIndex();
|
|
|
- }catch (Exception ex){
|
|
|
+ } catch (Exception ex) {
|
|
|
log.error(ex.toString());
|
|
|
return null;
|
|
|
}
|