Package org.zkoss.poi.ss.usermodel

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


      final VariableResolver resolver = BookHelper.getVariableResolver(book);
      final FunctionMapper mapper = BookHelper.getFunctionMapper(book);
      final XelContext ctx = new SimpleXelContext(resolver, mapper);
      ctx.setAttribute("zkoss.zss.CellType", Object.class);
      XelContextHolder.setXelContext(ctx);
      final CellValue cv = book.getFormulaEvaluator().evaluate(cell);
      //set back into Cell formula record(update value and cachedFormulaResultType)
      setCellValue(cell, cv);
      return cv;
    } finally {
      XelContextHolder.setXelContext(old);
View Full Code Here


  }
  public static RichTextString getText(Cell cell) {
    int cellType = cell.getCellType();
    if (cellType == Cell.CELL_TYPE_FORMULA) {
      final Book book = (Book)cell.getSheet().getWorkbook();
      final CellValue cv = BookHelper.evaluate(book, cell);
      cellType = cv.getCellType();
    } else if (cellType == Cell.CELL_TYPE_STRING) {
      return cell.getRichStringCellValue();
    }
      final String result = new DataFormatter(ZssContext.getCurrent().getLocale(), false).formatCellValue(cell, cellType); //ZSS-68
    return newRichTextString(cell, result);
View Full Code Here

  public static FormatTextImpl getFormatText(Cell cell) {
    int cellType = cell.getCellType();
        final String formatStr = cell.getCellStyle().getDataFormatString();
    if (cellType == Cell.CELL_TYPE_FORMULA) {
      final Book book = (Book)cell.getSheet().getWorkbook();
      final CellValue cv = BookHelper.evaluate(book, cell);
      cellType = cv.getCellType();
//      final Hyperlink hyperlink = cv.getEvalHyperlink();
//      if (hyperlink != null) { //might be HYPERLINK function
//        //do some special format?
//      }
    }
View Full Code Here

            if ((pasteType & BookHelper.INNERPASTE_FORMULAS) != 0) { //copy formula
              final Set<Ref>[] refs = copyCellFormula(dstCell, srcCell, transpose);
          assignRefs(toEval, affected, refs);
            } else { //copy evaluated value only
              final Book book = (Book) srcCell.getSheet().getWorkbook();
              final CellValue cv = evaluate(book, srcCell);
              final Set<Ref>[] refs = setCellValueByCellValue(dstCell, cv, pasteType, pasteOp);
          assignRefs(toEval, affected, refs);
            }
        break;
      default:
View Full Code Here

      return "";
    }
    int cellType = cell.getCellType();
    if (cellType == Cell.CELL_TYPE_FORMULA) {
      final Book book = (Book)cell.getSheet().getWorkbook();
      final CellValue cv = BookHelper.evaluate(book, cell);
      return BookHelper.getValueByCellValue(cv);
    } else {
      return BookHelper.getCellValue(cell);
    }
  }
View Full Code Here

      final VariableResolver resolver = BookHelper.getVariableResolver(book);
      final FunctionMapper mapper = BookHelper.getFunctionMapper(book);
      final XelContext ctx = new SimpleXelContext(resolver, mapper);
      ctx.setAttribute("zkoss.zss.CellType", Object.class);
      XelContextHolder.setXelContext(ctx);
      final CellValue cv = book.getFormulaEvaluator().evaluateFormula(sheetIndex, formula);
      return cv;
    } finally {
      XelContextHolder.setXelContext(old);
    }
  }
View Full Code Here

      case Cell.CELL_TYPE_FORMULA:
        final Book book = sheet.getBook();
        final int sheetIndex = book.getSheetIndex(sheet);
        return BookHelper.evaluateFormula(book, sheetIndex, (String) value);
      case Cell.CELL_TYPE_STRING:
        return new CellValue((String)value); //String
      case Cell.CELL_TYPE_BOOLEAN:
        return CellValue.valueOf(((Boolean)value).booleanValue()); //boolean
      case Cell.CELL_TYPE_NUMERIC:
        if (value instanceof Date) {
              boolean date1904 = sheet.getBook().isDate1904();
              double num = DateUtil.getExcelDate((Date)value, date1904);
          value = new Double(num);
        }
        return new CellValue(((Number)value).doubleValue());
      case Cell.CELL_TYPE_ERROR:
        return CellValue.getError(((Byte)value).intValue() & 0xff);
      }
    }
    return null;
View Full Code Here

    if (target == null) {
      return false;
    }
    String[] list = constraint.getExplicitListValues();
    if (list != null) {
      CellValue candidate = null;
      for(int j = 0; j < list.length; ++j) {
        String txt = list[j];
        if (txt == null) {
          continue; //skip
        } else if (txt.startsWith("=")) { //must be string
          candidate = new CellValue(txt);
        } else {
          candidate = getEvalValue(sheet, txt);
        }
        if (candidate != null && equalCellValue(target, candidate)) {
          return true;
        }
      }
      return false;
    } else {
      String txt = constraint.getFormula1();
      Book book = sheet.getBook();
      final ValueEval ve = BookHelper.evaluateFormulaValueEval(book, book.getSheetIndex(sheet), txt, false);
      if (ve instanceof ArrayEval) {
        final ArrayEval ae = (ArrayEval) ve;
        if (ae.isColumn() || ae.isRow()) {
          final int rows = ae.getHeight();
          final int cols = ae.getWidth();
          for (int r = 0; r < rows; ++r) {
            for (int c = 0; c < cols; ++c) {
              ValueEval xve = ae.getValue(r, c);
              final CellValue candidate = book.getFormulaEvaluator().getCellValueByValueEval(xve);
              if (equalCellValue(target, candidate)) {
                return true;
              }
            }
          }
        }
      } else {
        final CellValue candidate = book.getFormulaEvaluator().getCellValueByValueEval(ve);
        if (equalCellValue(target, candidate)) {
          return true;
        }
      }
      return false;
View Full Code Here

  private static boolean validateOperation(Worksheet sheet, DataValidationConstraint constraint, Number value) {
    if (value == null) {
      return false;
    }
    String f1 = constraint.getFormula1();
    CellValue cv1 = getEvalValue(sheet, f1);
    if (cv1 == null) {
      return true;
    }
    if (cv1.getCellType() != Cell.CELL_TYPE_NUMERIC) { //type does not match
      return false;
    }
    double v1 = cv1.getNumberValue();
    double v = value.doubleValue();
    switch(constraint.getOperator()) {
      case OperatorType.BETWEEN:
      {
        final String f2 = constraint.getFormula2();
        final CellValue cv2 = getEvalValue(sheet, f2);
        if (cv2.getCellType() != Cell.CELL_TYPE_NUMERIC) { //type does not match
          return false;
        }
        final double v2 = cv2.getNumberValue();
        return v >= v1 && v <= v2;
      }
      case OperatorType.NOT_BETWEEN:
      {
        final String f2 = constraint.getFormula2();
        final CellValue cv2 = getEvalValue(sheet, f2);
        if (cv2.getCellType() != Cell.CELL_TYPE_NUMERIC) { //type does not match
          return false;
        }
        final double v2 = cv2.getNumberValue();
        return v < v1 || v > v2;
      }
      case OperatorType.EQUAL:
        return v == v1;
      case OperatorType.NOT_EQUAL:
View Full Code Here

    }
    //get new evaluated formula value
    if (cellType == Cell.CELL_TYPE_FORMULA) {
      final Book book = sheet.getBook();
      final int sheetIndex = book.getSheetIndex(sheet);
      final CellValue cv = BookHelper.evaluateFormula(book, sheetIndex, (String) value);
      value = BookHelper.getValueByCellValue(cv);
      cellType = cv.getCellType();
    }
    //start validation
    boolean success = true;
    switch(constraint.getValidationType()) {
      // Integer ('Whole number') type
View Full Code Here

TOP

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

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.