Package org.zkoss.poi.ss.usermodel

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


    short indention,
    short borderLeft, short borderTop, short borderRight, short borderBottom,
    short borderLeftColor, short borderTopColor, short borderRightColor, short borderBottomColor,
    short fillPattern, short fillBackColor, short fillForeColor) {
    for(short j = 0, len = book.getNumCellStyles(); j < len; ++j) {
      CellStyle style = book.getCellStyleAt(j);
      if (style.getDataFormat() != dataFormat)
        continue;
      if (style.getFontIndex() != fontIndex)
        continue;
      if (style.getFillForegroundColor() != fillForeColor)
        continue;
      if (style.getHidden() != hidden)
        continue;
      if (style.getLocked() != locked)
        continue;
      if (style.getAlignment() != alignment)
        continue;
      if (style.getWrapText() != wrapText)
        continue;
      if (style.getVerticalAlignment() != valign)
        continue;
      if (style.getIndention() != indention)
        continue;
      if (style.getBorderLeft() != borderLeft)
        continue;
      if (style.getBorderTop() != borderTop)
        continue;
      if (style.getBorderRight() != borderRight)
        continue;
      if (style.getBorderBottom() != borderBottom)
        continue;
      if (style.getLeftBorderColor() != borderLeftColor)
        continue;
      if (style.getTopBorderColor() != borderTopColor)
        continue;
      if (style.getRightBorderColor() != borderRightColor)
        continue;
      if (style.getBottomBorderColor() != borderBottomColor)
        continue;
      if (style.getFillPattern() != fillPattern)
        continue;
      if (style.getFillBackgroundColor() != fillBackColor)
        continue;
      if (style.getRotation() != rotation)
        continue;
      return style; //found it!
    }
    return null;
  }
View Full Code Here


          break;
        }
      }
    }
   
    CellStyle style = null;
    if (target != null) { //found the target
      final int tgtRow = target.getRowIndex();
      final int tgtCol = target.getColumnIndex();
      final int nRow = tRow - tgtRow;
      final int nCol = lCol - tgtCol;
      if (nRow != 0 || nCol != 0) { //if target not the left-top one, move to left-top
        final ChangeInfo info = BookHelper.moveRange(sheet, tgtRow, tgtCol, tgtRow, tgtCol, nRow, nCol);
        if (info != null) {
          changes.addAll(info.getMergeChanges());
          last.addAll(info.getToEval());
          all.addAll(info.getAffected());
        }
      }
      final CellStyle source = target.getCellStyle();
      style = source.getIndex() == 0 ? null : sheet.getWorkbook().createCellStyle();
      if (style != null) {
        style.cloneStyleFrom(source);
        style.setBorderLeft(CellStyle.BORDER_NONE);
        style.setBorderTop(CellStyle.BORDER_NONE);
        style.setBorderRight(CellStyle.BORDER_NONE);
View Full Code Here

    }
    return font;
  }
 
  public static Font getFont(Cell cell) {
    final CellStyle style = cell.getCellStyle();
    final short fontIdx = style.getFontIndex();
    return cell.getSheet().getWorkbook().getFontAt(fontIdx);
  }
View Full Code Here

  //create a CellStyle of the book from the given source CellStyle
    /*package*/ static CellStyle copyFromStyleExceptBorder(Workbook book, CellStyle srcStyle) {
      if (srcStyle.getIndex() == 0) { //default one
        return srcStyle;
      }
      CellStyle dstStyle = book.createCellStyle();
    final short bb = dstStyle.getBorderBottom();
    final short tb = dstStyle.getBorderTop();
    final short lb = dstStyle.getBorderLeft();
    final short rb = dstStyle.getBorderRight();
    final short bc = dstStyle.getBottomBorderColor();
    final short tc = dstStyle.getTopBorderColor();
    final short lc = dstStyle.getLeftBorderColor();
    final short rc = dstStyle.getRightBorderColor();
    dstStyle.cloneStyleFrom(srcStyle);
    dstStyle.setBorderBottom(bb);
    dstStyle.setBorderTop(tb);
    dstStyle.setBorderLeft(lb);
    dstStyle.setBorderRight(rb);
    dstStyle.setBottomBorderColor(bc);
    dstStyle.setTopBorderColor(tc);
    dstStyle.setLeftBorderColor(lc);
    dstStyle.setRightBorderColor(rc);
   
    return dstStyle;
    }
View Full Code Here

      return raw;
    }
  }
 
  public static String getTextCSSStyle(Book book, Cell cell) {
    final CellStyle style = cell.getCellStyle();
    if (style == null)
      return "";

    final StringBuffer sb = new StringBuffer();
    int textHAlign = getRealAlignment(cell);
   
    switch(textHAlign) {
    case CellStyle.ALIGN_RIGHT:
      sb.append("text-align:").append("right").append(";");
      break;
    case CellStyle.ALIGN_CENTER:
    case CellStyle.ALIGN_CENTER_SELECTION:
      sb.append("text-align:").append("center").append(";");
      break;
    }

    boolean textWrap = style.getWrapText();
    if (textWrap) {
      sb.append("white-space:").append("normal").append(";");
    }/*else{ sb.append("white-space:").append("nowrap").append(";"); }*/

    return sb.toString();
View Full Code Here

  }

  /* given alignment and cell type, return real alignment */
  //Halignment determined by style alignment, text format and value type 
  public static int getRealAlignment(Cell cell) {
    CellStyle style = cell.getCellStyle();
    int type = cell.getCellType();
    int align = style.getAlignment();
    if (align == CellStyle.ALIGN_GENERAL) {
      final String format = style.getDataFormatString();
      if (format != null && format.startsWith("@")) //a text format
        type = Cell.CELL_TYPE_STRING;
      else if (type == Cell.CELL_TYPE_FORMULA)
        type = cell.getCachedFormulaResultType();
      switch(type) {
View Full Code Here

  }
 
  private static CellStyle prepareCellStyle(CellStyle srcStyle, Cell dstCell, int pasteType) {
    //TODO now assume same workbook in copying CellStyle.
    if ((pasteType & Range.PASTE_FORMATS) == BookHelper.INNERPASTE_NUMBER_FORMATS) { //number format only
      final CellStyle style = dstCell.getSheet().getWorkbook().createCellStyle();
      final CellStyle dstStyle = dstCell.getCellStyle();
      style.cloneStyleFrom(dstStyle);
      final short fmt = srcStyle.getDataFormat();
      style.setDataFormat(fmt);
      return style;
    }
    if ((pasteType & BookHelper.INNERPASTE_BORDERS) == 0) { //no border
      final CellStyle newStyle = dstCell.getSheet().getWorkbook().createCellStyle();
      final CellStyle dstStyle = dstCell.getCellStyle();
     
      final short borderLeft = dstStyle.getBorderLeft();
      final short borderTop = dstStyle.getBorderTop();
      final short borderRight = dstStyle.getBorderRight();
      final short borderBottom = dstStyle.getBorderBottom();
      final short borderLeftColor = dstStyle.getLeftBorderColor();
      final short borderTopColor = dstStyle.getTopBorderColor();
      final short borderRightColor = dstStyle.getRightBorderColor();
      final short borderBottomColor = dstStyle.getBottomBorderColor();
     
      newStyle.cloneStyleFrom(srcStyle);
      newStyle.setBorderLeft(borderLeft );
      newStyle.setBorderTop(borderTop);
      newStyle.setBorderRight(borderRight);
View Full Code Here

     
      //width, height id
      if (updateSize) {
        if (cell != null) {
          //process overflow when cell type is string, halign is left, no wrap, no merge
          CellStyle cellStyle = cell.getCellStyle();
          if (cell.getCellType() == Cell.CELL_TYPE_STRING &&
            mergeIndex == null && !cellStyle.getWrapText() &&
            BookHelper.getRealAlignment(cell) == CellStyle.ALIGN_LEFT) {
           
            attrs.put("ovf", 1); //1 stand for true
            int c = getMaxOverflowableCellIndex(cell, sheet.getRow(row));
            if (c != col) {
              attrs.put("moc", c);
            }
          }
        }
      }
     
      //style attr
      if (updateStyle) {
        CellFormatHelper cfh = new CellFormatHelper(sheet, row, col, getMergeMatrixHelper(sheet));
        String style = cfh.getHtmlStyle();
        if (!Strings.isEmpty(style)) {
          int idx = styleAggregation.add(style);
          attrs.put("s", idx);
        }
        String innerStyle = cfh.getInnerHtmlStyle();
        if (!Strings.isEmpty(innerStyle)) {
          int idx = styleAggregation.add(innerStyle);
          attrs.put("is", idx);
        }
        if (cfh.hasRightBorder()) {
          attrs.put("rb", 1);
        }
      }
     
      if (cell != null) {
        int cellType = cell.getCellType();
        if (cellType != Cell.CELL_TYPE_BLANK)
          attrs.put("ct", cellType);
       
        if (updateText) {
          if (cellType != Cell.CELL_TYPE_BLANK) {
            final String cellText = getCelltext(sheet, row, col);
            final String editText = getEdittext(sheet, row, col);
            final String formatText = getCellFormatText(sheet, row, col);
           
            if (Objects.equals(cellText, editText) && Objects.equals(editText, formatText)) {
              attrs.put("meft", textAggregation.add(cellText));
            } else {
              attrs.put("t", textAggregation.add(cellText));
              attrs.put("et", textAggregation.add(editText));
              attrs.put("ft", textAggregation.add(formatText));
            }
          }
        }
       
        if (updateStyle) {
          CellStyle cellStyle = cell.getCellStyle();
          boolean locked = cellStyle.getLocked();
          if (!locked)
            attrs.put("l", "f"); //f stand for "false"
         
          boolean wrap = cellStyle.getWrapText();
          if (wrap)
            attrs.put("wp", 1);
         
          int horizontalAlignment = BookHelper.getRealAlignment(cell);
          switch(horizontalAlignment) {
          case CellStyle.ALIGN_CENTER:
          case CellStyle.ALIGN_CENTER_SELECTION:
            attrs.put("ha", "c");
            break;
          case CellStyle.ALIGN_RIGHT:
            attrs.put("ha", "r");
            break;
          }
         
          int verticalAlignment = cellStyle.getVerticalAlignment();
          switch(verticalAlignment) {
          case CellStyle.VERTICAL_TOP:
            attrs.put("va", "t");
            break;
          case CellStyle.VERTICAL_CENTER:
            attrs.put("va", "c");
            break;
          //case CellStyle.VERTICAL_BOTTOM: //default
          //  break;
          }
         
          Font font = _book.getFontAt(cellStyle.getFontIndex());
          short fontHeight = font.getFontHeightInPoints();
          if (fontHeight != XSSFFont.DEFAULT_FONT_SIZE) {
            attrs.put("fs", fontHeight);
          }
        }
View Full Code Here

    String ret = ctrl.getRangeAttrs(sheet, SpreadsheetCtrl.Header.NONE, SpreadsheetCtrl.CellAttribute.ALL, left, top, right, bottom).toJSONString();
    response(bottom + "_" + right + "_" + _updateRangeId.next(), new AuUpdateData(this, AuUpdateData.UPDATE_RANGE_FUNCTION, "", sheetId, ret));
  }
 
  public void escapeAndUpdateText(Cell cell, String text) {
    final CellStyle style = (cell == null) ? null : cell.getCellStyle();
    final boolean wrap = style != null && style.getWrapText();
    text = Utils.escapeCellText(text, wrap, true);
    updateText(cell, text);
  }
View Full Code Here

      final Workbook book = sheet.getWorkbook();
     
      for(int row = tRow; row <= bRow; ++row) {
        for (int col = lCol; col <= rCol; ++col) {
          final Cell cell = BookHelper.getCell(sheet, row, col);
          final CellStyle style = cell != null ? cell.getCellStyle() : null;
          final String oldFormat = style != null ? style.getDataFormatString() : null;
          if (oldFormat == null || "General".equals(oldFormat)) {
            CellStyle newCellStyle = book.createCellStyle();
            if (style != null) {
              newCellStyle.cloneStyleFrom(style);
            }
            BookHelper.setDataFormat(book, newCellStyle, formatString); //prepare a DataFormat with the specified formatString
            BookHelper.setCellStyle(sheet, row, col, row, col, newCellStyle);
          }
        }
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.