Package com.narirelays.ems.utils.excel

Examples of com.narirelays.ems.utils.excel.ColorModel


       * 需要检查web sheet返回的结果中为什么没有border-top和border-bottom
       */
      if(styleMap.containsKey("border-top-style")){
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-top-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-top-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setTopBorderColor(index);
            }else{
              style.setTopBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setTopBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderTop(HSSFCellStyle.BORDER_NONE);
      }
      if(styleMap.containsKey("border-bottom-style")){
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-bottom-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-bottom-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setBottomBorderColor(index);
            }else{
              style.setBottomBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
      }
      if(styleMap.containsKey("border-left-style")){
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-left-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-left-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setLeftBorderColor(index);
            }else{
              style.setLeftBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
      }     
      if(styleMap.containsKey("border-right-style")){
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-right-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-right-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setRightBorderColor(index);
            }else{
              style.setRightBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setRightBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderRight(HSSFCellStyle.BORDER_NONE);
     
     
      if(styleMap.containsKey("border-style")){
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setTopBorderColor(index);
              style.setBottomBorderColor(index);
              style.setRightBorderColor(index);
              style.setLeftBorderColor(index);
            }else{
              style.setTopBorderColor(hssfColor.getIndex());
              style.setBottomBorderColor(hssfColor.getIndex());
              style.setRightBorderColor(hssfColor.getIndex());
              style.setLeftBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setTopBorderColor(IndexedColors.BLACK.getIndex());
            style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
            style.setRightBorderColor(IndexedColors.BLACK.getIndex());
            style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setTopBorderColor(IndexedColors.BLACK.getIndex());
          style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
          style.setRightBorderColor(IndexedColors.BLACK.getIndex());
          style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        }
      }
     
//      style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//      style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
//      style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//      style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
//      style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//      style.setRightBorderColor(IndexedColors.BLACK.getIndex());
//      style.setBorderTop(HSSFCellStyle.BORDER_THIN);
//      style.setTopBorderColor(IndexedColors.BLACK.getIndex());
     
      // 设置相关值
      // 背景色 background-color
     
     
      if (styleMap.containsKey("background-color")) {
        String colorValue = styleMap.get("background-color");
        ColorModel color = ColorModel.parseRGBString(colorValue);
        if (color != null) {
          HSSFColor hssfColor = palette.findColor((byte) color.r,
              (byte) color.g, (byte) color.b);
          if (hssfColor == null) {
            short index = styleContainer.getNextColorIndex();
            palette.setColorAtIndex(index,(byte) color.r,
                (byte) color.g, (byte) color.b);
            style.setFillForegroundColor(index);
          }else{
            style.setFillForegroundColor(hssfColor.getIndex());
          }
          style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }
      }
     
      if (td.hasAttr("bgcolor")) {
        String colorValue = td.attr("bgcolor");
        ColorModel color = ColorModel.parseRGBString(colorValue);
        if (color != null) {
          HSSFColor hssfColor = palette.findColor((byte) color.r,
              (byte) color.g, (byte) color.b);
          if (hssfColor == null) {
            short index = styleContainer.getNextColorIndex();
            palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
            style.setFillForegroundColor(index);
          }else{
            style.setFillForegroundColor(hssfColor.getIndex());
          }
          style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }
      }

      // 设置字体相关
      // font-family
      if (styleMap.containsKey("font-family")) {
        String font_family = styleMap.get("font-family");
        font.setFontName(font_family);
      }
      // 字体颜色
      if (styleMap.containsKey("color")) {
        String colorValue = styleMap.get("color");
        ColorModel color = ColorModel.parseRGBString(colorValue);
        if (color != null) {
          HSSFColor hssfColor = palette.findColor((byte) color.r,
              (byte) color.g, (byte) color.b);
          if (hssfColor == null) {
            short index = styleContainer.getNextColorIndex();
View Full Code Here

TOP

Related Classes of com.narirelays.ems.utils.excel.ColorModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.