Package org.openxmlformats.schemas.spreadsheetml.x2006.main

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor


    }

    XSSFColor color = null;
    color = style.getTopBorderXSSFColor();
    if(color!=null){
      CTColor ctColor = color.getCTColor();
      if(ctColor!=null){
        if(ctColor.isSetRgb()){
          byte[] rgb = ctColor.getRgb();
          if(rgb.length==3){
            css(td,"border-top-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
          }else if(rgb.length==4){
            css(td,"border-top-color",String.format("#%02x%02x%02x", rgb[1],rgb[2],rgb[3]));
          }
        }else{
          css(td,"border-top-color","#000000");
        }
      }else{
        css(td,"border-top-color","#000000");
      }
    }
   
    switch(style.getBorderBottom()){
    case CellStyle.BORDER_THICK:
    case CellStyle.BORDER_MEDIUM:
    case CellStyle.BORDER_THIN:
      css(td,"border-bottom-style","solid");
      break;
    case CellStyle.BORDER_DASH_DOT:
    case CellStyle.BORDER_DASH_DOT_DOT:
    case CellStyle.BORDER_DASHED:
      css(td,"border-bottom-style","dashed");
      break;
    case CellStyle.BORDER_DOTTED:
    case CellStyle.BORDER_DOUBLE:
    case CellStyle.BORDER_HAIR:
    case CellStyle.BORDER_MEDIUM_DASH_DOT:
    case CellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
    case CellStyle.BORDER_MEDIUM_DASHED:
    case CellStyle.BORDER_SLANTED_DASH_DOT:
      css(td,"border-bottom-style","dotted");
      break;
    }
   
    color = style.getBottomBorderXSSFColor();
    if(color!=null){
      CTColor ctColor = color.getCTColor();
      if(ctColor!=null){
        if(ctColor.isSetRgb()){
          byte[] rgb = ctColor.getRgb();
          if(rgb.length==3){
            css(td,"border-bottom-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
          }else if(rgb.length==4){
            css(td,"border-bottom-color",String.format("#%02x%02x%02x", rgb[1],rgb[2],rgb[3]));
          }
        }else{
          css(td,"border-bottom-color","#000000");
        }
      }else{
        css(td,"border-bottom-color","#000000");
      }
       
    }

   
    switch(style.getBorderLeft()){
    case CellStyle.BORDER_THICK:
    case CellStyle.BORDER_MEDIUM:
    case CellStyle.BORDER_THIN:
      css(td,"border-left-style","solid");
      break;
    case CellStyle.BORDER_DASH_DOT:
    case CellStyle.BORDER_DASH_DOT_DOT:
    case CellStyle.BORDER_DASHED:
      css(td,"border-left-style","dashed");
      break;
    case CellStyle.BORDER_DOTTED:
    case CellStyle.BORDER_DOUBLE:
    case CellStyle.BORDER_HAIR:
    case CellStyle.BORDER_MEDIUM_DASH_DOT:
    case CellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
    case CellStyle.BORDER_MEDIUM_DASHED:
    case CellStyle.BORDER_SLANTED_DASH_DOT:
      css(td,"border-left-style","dotted");
      break;
    }
   
    color = style.getLeftBorderXSSFColor();
    if(color!=null){
      CTColor ctColor = color.getCTColor();
      if(ctColor!=null){
        if(ctColor.isSetRgb()){
          byte[] rgb = ctColor.getRgb();
          if(rgb.length==3){
            css(td,"border-left-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
          }else if(rgb.length==4){
            css(td,"border-left-color",String.format("#%02x%02x%02x", rgb[1],rgb[2],rgb[3]));
          }
        }else{
          css(td,"border-left-color","#000000");
        }
      }else{
        css(td,"border-left-color","#000000");
      }
    }
   
    switch(style.getBorderRight()){
    case CellStyle.BORDER_THICK:
    case CellStyle.BORDER_MEDIUM:
    case CellStyle.BORDER_THIN:
      css(td,"border-right-style","solid");
      break;
    case CellStyle.BORDER_DASH_DOT:
    case CellStyle.BORDER_DASH_DOT_DOT:
    case CellStyle.BORDER_DASHED:
      css(td,"border-right-style","dashed");
      break;
    case CellStyle.BORDER_DOTTED:
    case CellStyle.BORDER_DOUBLE:
    case CellStyle.BORDER_HAIR:
    case CellStyle.BORDER_MEDIUM_DASH_DOT:
    case CellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
    case CellStyle.BORDER_MEDIUM_DASHED:
    case CellStyle.BORDER_SLANTED_DASH_DOT:
      css(td,"border-right-style","dotted");
      break;
    }
   
    color = style.getRightBorderXSSFColor();
    if(color!=null){
      CTColor ctColor = color.getCTColor();
      if(ctColor!=null){
        if(ctColor.isSetRgb()){
          byte[] rgb = ctColor.getRgb();
          if(rgb.length==3){
            css(td,"border-right-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
          }else if(rgb.length==4){
            css(td,"border-right-color",String.format("#%02x%02x%02x", rgb[1],rgb[2],rgb[3]));
          }
        }else{
          css(td,"border-right-color","#000000");
        }
      }else{
        css(td,"border-right-color","#000000");
      }
    }
   

//    color = style.getFillForegroundXSSFColor();
//    if(color!=null){
//      CTColor ctColor = color.getCTColor();
//      if(ctColor!=null){
//        if(ctColor.isSetRgb()){
//          byte[] rgb = ctColor.getRgb();
//          if(rgb.length==3){
//            css(td,"background-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
//          }else if(rgb.length==4){
//            css(td,"background-color",String.format("#%02x%02x%02x", rgb[1],rgb[2],rgb[3]));
//          }
//        }else{
//          css(td,"background-color","#ffffff");
//        }
//      }else{
//        css(td,"background-color","#ffffff");
//      }
//    }
   
    color = style.getFillBackgroundXSSFColor();
    if(color!=null){
      CTColor ctColor = color.getCTColor();
      if(ctColor!=null){
        if(ctColor.isSetRgb()){
          byte[] rgb = ctColor.getRgb();
          if(rgb.length==3){
            css(td,"background-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
          }else if(rgb.length==4){
            css(td,"background-color",String.format("#%02x%02x%02x", rgb[1],rgb[2],rgb[3]));
          }
        }else{
          css(td,"background-color","#ffffff");
        }
      }else{
        css(td,"background-color","#ffffff");
      }
    }
   
   
    XSSFFont font = style.getFont();
    if(font!=null){
      css(td,"font-family",font.getFontName());
      color = font.getXSSFColor();
      if(color!=null){
        CTColor ctColor = color.getCTColor();
        if(ctColor!=null){
          if(ctColor.isSetRgb()){
            byte[] rgb = ctColor.getRgb();
            if(rgb.length==3){
              if(rgb[0]==-1&&rgb[1]==-1&&rgb[2]==-1){
                css(td,"color","#000000");
              }else{
                css(td,"color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
View Full Code Here


     * @param colorIndex  the indexed color to set, must be a constant from {@link IndexedColors}
     */
    public void setTabColor(int colorIndex){
        CTSheetPr pr = worksheet.getSheetPr();
        if(pr == null) pr = worksheet.addNewSheetPr();
        CTColor color = CTColor.Factory.newInstance();
        color.setIndexed(colorIndex);
        pr.setTabColor(color);
    }
View Full Code Here

     * @param colorIndex  the indexed color to set, must be a constant from {@link IndexedColors}
     */
    public void setTabColor(int colorIndex){
        CTSheetPr pr = worksheet.getSheetPr();
        if(pr == null) pr = worksheet.addNewSheetPr();
        CTColor color = CTColor.Factory.newInstance();
        color.setIndexed(colorIndex);
        pr.setTabColor(color);
    }
View Full Code Here

     */
    public short getFontColorIndex(){
        if(_font.sizeOfColorArray() == 0) return -1;

        int idx = 0;
        CTColor color = _font.getColorArray(0);
        if(color.isSetIndexed()) idx = (int)color.getIndexed();
        return (short)idx;
    }
View Full Code Here

    private void setRunAttributes(CTFont ctFont, CTRPrElt pr){
        if(ctFont.sizeOfBArray() > 0) pr.addNewB().setVal(ctFont.getBArray(0).getVal());
        if(ctFont.sizeOfUArray() > 0) pr.addNewU().setVal(ctFont.getUArray(0).getVal());
        if(ctFont.sizeOfIArray() > 0) pr.addNewI().setVal(ctFont.getIArray(0).getVal());
        if(ctFont.sizeOfColorArray() > 0) {
            CTColor c1 = ctFont.getColorArray(0);
            CTColor c2 = pr.addNewColor();
            if(c1.isSetAuto()) c2.setAuto(c1.getAuto());
            if(c1.isSetIndexed()) c2.setIndexed(c1.getIndexed());
            if(c1.isSetRgb()) c2.setRgb(c1.getRgb());
            if(c1.isSetTheme()) c2.setTheme(c1.getTheme());
            if(c1.isSetTint()) c2.setTint(c1.getTint());
        }
        if(ctFont.sizeOfSzArray() > 0) pr.addNewSz().setVal(ctFont.getSzArray(0).getVal());
        if(ctFont.sizeOfNameArray() > 0) pr.addNewRFont().setVal(ctFont.getNameArray(0).getVal());
        if(ctFont.sizeOfFamilyArray() > 0) pr.addNewFamily().setVal(ctFont.getFamilyArray(0).getVal());
        if(ctFont.sizeOfSchemeArray() > 0) pr.addNewScheme().setVal(ctFont.getSchemeArray(0).getVal());
View Full Code Here

        if(pr.sizeOfBArray() > 0) ctFont.addNewB().setVal(pr.getBArray(0).getVal());
        if(pr.sizeOfUArray() > 0) ctFont.addNewU().setVal(pr.getUArray(0).getVal());
        if(pr.sizeOfIArray() > 0) ctFont.addNewI().setVal(pr.getIArray(0).getVal());
        if(pr.sizeOfColorArray() > 0) {
            CTColor c1 = pr.getColorArray(0);
            CTColor c2 = ctFont.addNewColor();
            if(c1.isSetAuto()) c2.setAuto(c1.getAuto());
            if(c1.isSetIndexed()) c2.setIndexed(c1.getIndexed());
            if(c1.isSetRgb()) c2.setRgb(c1.getRgb());
            if(c1.isSetTheme()) c2.setTheme(c1.getTheme());
            if(c1.isSetTint()) c2.setTint(c1.getTint());
        }
        if(pr.sizeOfSzArray() > 0) ctFont.addNewSz().setVal(pr.getSzArray(0).getVal());
        if(pr.sizeOfRFontArray() > 0) ctFont.addNewName().setVal(pr.getRFontArray(0).getVal());
        if(pr.sizeOfFamilyArray() > 0) ctFont.addNewFamily().setVal(pr.getFamilyArray(0).getVal());
        if(pr.sizeOfSchemeArray() > 0) ctFont.addNewScheme().setVal(pr.getSchemeArray(0).getVal());
View Full Code Here

    assertEquals(STUnderlineValues.DOUBLE_ACCOUNTING,ctFont.getUArray(0).getVal());
  }

  public void testColor() {
    CTFont ctFont=CTFont.Factory.newInstance();
    CTColor color=ctFont.addNewColor();
    color.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
    ctFont.setColorArray(0,color);

    XSSFFont xssfFont=new XSSFFont(ctFont);
    assertEquals(IndexedColors.BLACK.getIndex(),xssfFont.getColor());
View Full Code Here

    assertEquals(IndexedColors.RED.getIndex(), ctFont.getColorArray(0).getIndexed());
  }

  public void testRgbColor() {
    CTFont ctFont=CTFont.Factory.newInstance();
    CTColor color=ctFont.addNewColor();

    color.setRgb(Integer.toHexString(0xFFFFFF).getBytes());
    ctFont.setColorArray(0,color);

    XSSFFont xssfFont=new XSSFFont(ctFont);
    assertEquals(ctFont.getColorArray(0).getRgb()[0],xssfFont.getXSSFColor().getRgb()[0]);
    assertEquals(ctFont.getColorArray(0).getRgb()[1],xssfFont.getXSSFColor().getRgb()[1]);
    assertEquals(ctFont.getColorArray(0).getRgb()[2],xssfFont.getXSSFColor().getRgb()[2]);
    assertEquals(ctFont.getColorArray(0).getRgb()[3],xssfFont.getXSSFColor().getRgb()[3]);

    color.setRgb(Integer.toHexString(0xF1F1F1).getBytes());
    XSSFColor newColor=new XSSFColor(color);
    xssfFont.setColor(newColor);
    assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRgb()[2]);
  }
View Full Code Here

    assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRgb()[2]);
  }

  public void testThemeColor() {
    CTFont ctFont=CTFont.Factory.newInstance();
    CTColor color=ctFont.addNewColor();
    color.setTheme(1);
    ctFont.setColorArray(0,color);

    XSSFFont xssfFont=new XSSFFont(ctFont);
    assertEquals(ctFont.getColorArray(0).getTheme(),xssfFont.getThemeColor());
View Full Code Here

        val < 1 ? 1.055 * Math.pow(val, (1d / 2.4)) - 0.055 : 1;
  }
*/
  private static String XSSFColorToHTML(XSSFWorkbook book, XSSFColor color) {
    if (color != null) {
      final CTColor ctcolor = color.getCTColor();
      if (ctcolor.isSetIndexed()) {
        byte[] rgb = IndexedRGB.getRGB(color.getIndexed());
        if (rgb != null) {
          return "#"+ toHex(rgb[0])+ toHex(rgb[1])+ toHex(rgb[2]);
        }
      }
      if (ctcolor.isSetRgb()) {
        byte[] argb = ctcolor.isSetTint() ?
          getRgbWithTint(color.getRgb(), color.getTint())/*color.getRgbWithTint()*/ : color.getRgb();
        return argb.length > 3 ?
          "#"+ toHex(argb[1])+ toHex(argb[2])+ toHex(argb[3])://ignore alpha
          "#"+ toHex(argb[0])+ toHex(argb[1])+ toHex(argb[2]);
      }
      if (ctcolor.isSetTheme()) {
          ThemesTable theme = book.getTheme();
          if (theme != null) {
            XSSFColor themecolor = theme.getThemeColor(color.getTheme());
            if (themecolor != null) {
              if (ctcolor.isSetTint()) {
                themecolor.setTint(ctcolor.getTint());
              }
              return XSSFColorToHTML(book, themecolor); //recursive
            }
          }
      }
View Full Code Here

TOP

Related Classes of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor

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.