Package org.zkoss.poi.ss.usermodel

Examples of org.zkoss.poi.ss.usermodel.CellStyle


      @Override
      public void handle(CellVisitorContext context) {
        final boolean srcWrapText = context.isWrapText();

        if (srcWrapText != wrapped) {
          CellStyle newStyle = context.cloneCellStyle();
          newStyle.setWrapText(wrapped);
          context.getRange().setStyle(newStyle);
        }
      }});
  }
View Full Code Here


      @Override
      public void handle(CellVisitorContext context) {
        final boolean srcLocked = context.getLocked();

        if (srcLocked != locked) {
          CellStyle newStyle = context.cloneCellStyle();
          newStyle.setLocked(locked);
          context.getRange().setStyle(newStyle);
        }
      }});
  }
View Full Code Here

       
        DataFormat dataFormat = context.getBook().createDataFormat();
        short dstFormat = dataFormat.getFormat(format);
       
        if (srcFormat != dstFormat) {
          CellStyle newStyle = context.cloneCellStyle();
          newStyle.setDataFormat(dstFormat);
          context.getRange().setStyle(newStyle);
        }
      }
    });
  }
View Full Code Here

    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();
        if (patternType == CellStyle.NO_FILL) {
          newCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        }
        BookHelper.setFillForegroundColor(newCellStyle, bsColor);
        Range rng = Utils.getRange(sheet, row, col);
        rng.setStyle(newCellStyle);
      }
View Full Code Here

    Range range = getRange((Worksheet)cell.getSheet(), cell.getRowIndex(), cell.getColumnIndex());
    return range.getFormatText();
  }
 
  public static String getCellText(Worksheet sheet, Cell cell) {
    CellStyle style = (cell == null) ? null : cell.getCellStyle();
    boolean wrap = style != null && style.getWrapText();
    Hyperlink hlink = cell == null ? null : Utils.getHyperlink(cell);
    final FormatText ft = (cell == null) ? null : Utils.getFormatText(cell);
   
    final RichTextString rstr = ft != null && ft.isRichTextString() ? ft.getRichTextString() : null;
    String text = rstr != null ? Utils.formatRichTextString(sheet, rstr, wrap) : ft != null ? Utils.escapeCellText(ft.getCellFormatResult().text, wrap, true) : "";
View Full Code Here

      if(rect!=null){
        hitMerge = true;
        right = Utils.getCell(_sheet, _row, rect.getRight());
      }
      if (right != null) {
        CellStyle style = right.getCellStyle();
        if (style != null){
          int bb = style.getBorderRight();
          //String color = BookHelper.indexToRGB(_book, style.getRightBorderColor());
          String color = BookHelper.colorToHTML(_book, style.getRightBorderColorColor());
          hitRight = appendBorderStyle(sb, "right", bb, color);
        }
      }
    }

    Cell next = null;
    //if no border for target cell,then check is this cell in a merge range
    //if(true) then try to get next cell after this merge range
    //else get next cell of this cell
    if(!hitRight){
      int c = hitMerge?rect.getRight()+1:_col+1;
      next = Utils.getCell(_sheet, _row, c);
      //find the right cell of merge range.
      if(next!=null){
        CellStyle style = next.getCellStyle();
        if (style != null){
          int bb = style.getBorderLeft();//get left here
          //String color = BookHelper.indexToRGB(_book, style.getLeftBorderColor());
          //ZSS-34 cell background color does not show in excel
          String color = style.getFillPattern() != CellStyle.NO_FILL ?
              BookHelper.colorToHTML(_book, style.getLeftBorderColorColor()) : null;
            hitRight = appendBorderStyle(sb, "right", bb, color);
        }
      }
    }

    //border depends on next cell's background color
    if(!hitRight && next !=null){
      CellStyle style = next.getCellStyle();
      if (style != null){
        //String bgColor = BookHelper.indexToRGB(_book, style.getFillForegroundColor());
        //ZSS-34 cell background color does not show in excel
        String bgColor = style.getFillPattern() != CellStyle.NO_FILL ?
            BookHelper.colorToHTML(_book, style.getFillForegroundColorColor()) : null;
        if (BookHelper.AUTO_COLOR.equals(bgColor)) {
          bgColor = null;
        }
       
        if (bgColor != null) {
          hitRight = appendBorderStyle(sb, "right", CellStyle.BORDER_THIN, bgColor);
        }
      }
    }
    //border depends on current cell's background color
    if(!hitRight && _cell !=null){
      CellStyle style = _cell.getCellStyle();
      if (style != null){
        //String bgColor = BookHelper.indexToRGB(_book, style.getFillForegroundColor());
        //ZSS-34 cell background color does not show in excel
        String bgColor = style.getFillPattern() != CellStyle.NO_FILL ?
            BookHelper.colorToHTML(_book, style.getFillForegroundColorColor()) : null;
        if (BookHelper.AUTO_COLOR.equals(bgColor)) {
          bgColor = null;
        }
        if (bgColor != null) {
          hitRight = appendBorderStyle(sb, "right", CellStyle.BORDER_THIN, bgColor);
View Full Code Here

    return true;
  }

  public String getInnerHtmlStyle() {
    if (_cell != null) {
      CellStyle style = _cell.getCellStyle();
      if (style == null)
        return "";
     
      final StringBuffer sb = new StringBuffer();
      sb.append(BookHelper.getTextCSSStyle(_book, _cell));
     
      //vertical alignment
      int verticalAlignment = style.getVerticalAlignment();
      sb.append("display: table-cell;");
      switch (verticalAlignment) {
      case CellStyle.VERTICAL_TOP:
        sb.append("vertical-align: top;");
        break;
      case CellStyle.VERTICAL_CENTER:
        sb.append("vertical-align: middle;");
        break;
      case CellStyle.VERTICAL_BOTTOM:
        sb.append("vertical-align: bottom;");
        break;
      }
     
      final Font font = _book.getFontAt(style.getFontIndex());
     
      //sb.append(BookHelper.getFontCSSStyle(_book, font));
      sb.append(BookHelper.getFontCSSStyle(_cell, font));

      //condition color
View Full Code Here

*/
public class Styles {
  private static final Log log = Log.lookup(Styles.class);
 
  public static CellStyle cloneCellStyle(Cell cell) {
    final CellStyle destination = cell.getSheet().getWorkbook().createCellStyle();
    destination.cloneStyleFrom(cell.getCellStyle());
    return destination;
  }
View Full Code Here

    final boolean italic = font.getItalic();
    final boolean strikeout = font.getStrikeout();
    final short typeOffset = font.getTypeOffset();
    final byte underline = font.getUnderline();
    final Font newFont = BookHelper.getOrCreateFont(book, boldWeight, newColor, fontHeight, name, italic, strikeout, typeOffset, underline);
    final CellStyle style = cloneCellStyle(cell);
    style.setFont(newFont);
    cell.setCellStyle(style);
  }
View Full Code Here

    final Color orgColor = cell.getCellStyle().getFillForegroundColorColor();
    final Color newColor = BookHelper.HTMLToColor(book, color);
    if (orgColor == newColor || orgColor != null  && orgColor.equals(newColor)) { //no change, skip
      return;
    }
    final CellStyle style = cloneCellStyle(cell);
    BookHelper.setFillForegroundColor(style, newColor);
    cell.setCellStyle(style);
  }
View Full Code Here

TOP

Related Classes of org.zkoss.poi.ss.usermodel.CellStyle

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.