コード例 #1
0
  /**
   * Gets the formula present in the validation
   *
   * @return the validation formula as a string
   * @exception FormulaException
   */
  String getValidationFormula() throws FormulaException {
    if (type == LIST) {
      return formula1.getFormula();
    }

    String s1 = formula1.getFormula();
    String s2 = formula2 != null ? formula2.getFormula() : null;
    return condition.getConditionString(s1, s2) + "; x " + type.getDescription();
  }
コード例 #2
0
  /**
   * Removes a column
   *
   * @param col the row to remove
   */
  public void removeColumn(int col) {
    if (formula1 != null) {
      formula1.columnRemoved(0, col, true);
    }

    if (formula2 != null) {
      formula2.columnRemoved(0, col, true);
    }

    if (column1 > col) {
      column1--;
    }

    if (column2 >= col && column2 != MAX_COLUMNS) {
      column2--;
    }
  }
コード例 #3
0
  /**
   * Removes a row
   *
   * @param row the row to insert
   */
  public void removeRow(int row) {
    if (formula1 != null) {
      formula1.rowRemoved(0, row, true);
    }

    if (formula2 != null) {
      formula2.rowRemoved(0, row, true);
    }

    if (row1 > row) {
      row1--;
    }

    if (row2 >= row) {
      row2--;
    }
  }
コード例 #4
0
  /**
   * Inserts a column
   *
   * @param col the column to insert
   */
  public void insertColumn(int col) {
    if (formula1 != null) {
      formula1.columnInserted(0, col, true);
    }

    if (formula2 != null) {
      formula2.columnInserted(0, col, true);
    }

    if (column1 >= col) {
      column1++;
    }

    if (column2 >= col && column2 != MAX_COLUMNS) {
      column2++;
    }
  }
コード例 #5
0
  /**
   * Inserts a row
   *
   * @param row the row to insert
   */
  public void insertRow(int row) {
    if (formula1 != null) {
      formula1.rowInserted(0, row, true);
    }

    if (formula2 != null) {
      formula2.rowInserted(0, row, true);
    }

    if (row1 >= row) {
      row1++;
    }

    if (row2 >= row && row2 != MAX_ROWS) {
      row2++;
    }
  }
コード例 #6
0
  /**
   * Gets the raw bytes for the formula. This will include the parsed tokens array. Used when
   * copying spreadsheets
   *
   * @return the raw record data
   * @exception FormulaException
   */
  public byte[] getFormulaData() throws FormulaException {
    if (!getSheet().getWorkbookBof().isBiff8()) {
      throw new FormulaException(FormulaException.BIFF8_SUPPORTED);
    }

    // Get the tokens, taking into account the mapping from shared
    // formula specific values into normal values
    FormulaParser fp =
        new FormulaParser(
            getTokens(),
            this,
            getExternalSheet(),
            getNameTable(),
            getSheet().getWorkbook().getSettings());
    fp.parse();
    byte[] rpnTokens = fp.getBytes();

    byte[] data = new byte[rpnTokens.length + 22];

    // Set the standard info for this cell
    IntegerHelper.getTwoBytes(getRow(), data, 0);
    IntegerHelper.getTwoBytes(getColumn(), data, 2);
    IntegerHelper.getTwoBytes(getXFIndex(), data, 4);

    data[6] = (byte) 0x02; // indicates this cell is an error value
    data[8] = (byte) errorCode;
    data[12] = (byte) 0xff;
    data[13] = (byte) 0xff;

    // Now copy in the parsed tokens
    System.arraycopy(rpnTokens, 0, data, 22, rpnTokens.length);
    IntegerHelper.getTwoBytes(rpnTokens.length, data, 20);

    // Lop off the standard information
    byte[] d = new byte[data.length - 6];
    System.arraycopy(data, 6, d, 0, data.length - 6);

    return d;
  }
コード例 #7
0
  /** Called by the cell value when the cell features are added to the sheet */
  public void setCell(int col, int row, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws)
      throws FormulaException {
    // If this is part of an extended cells validation, then do nothing
    // as this will already have been called and parsed when the top left
    // cell was added
    if (extendedCellsValidation) {
      return;
    }

    row1 = row;
    row2 = row;
    column1 = col;
    column2 = col;

    formula1 = new FormulaParser(formula1String, es, nt, ws, ParseContext.DATA_VALIDATION);
    formula1.parse();

    if (formula2String != null) {
      formula2 = new FormulaParser(formula2String, es, nt, ws, ParseContext.DATA_VALIDATION);
      formula2.parse();
    }
  }
コード例 #8
0
  /** Gets the data */
  public byte[] getData() {
    // Compute the length of the data
    byte[] f1Bytes = formula1 != null ? formula1.getBytes() : new byte[0];
    byte[] f2Bytes = formula2 != null ? formula2.getBytes() : new byte[0];
    int dataLength =
        4
            + // the options
            promptTitle.length() * 2
            + 3
            + // the prompt title
            errorTitle.length() * 2
            + 3
            + // the error title
            promptText.length() * 2
            + 3
            + // the prompt text
            errorText.length() * 2
            + 3
            + // the error text
            f1Bytes.length
            + 2
            + // first formula
            f2Bytes.length
            + 2
            + // second formula
            +4
            + // unused bytes
            10; // cell range

    byte[] data = new byte[dataLength];

    // The position
    int pos = 0;

    // The options
    int options = 0;
    options |= type.getValue();
    options |= errorStyle.getValue() << 4;
    options |= condition.getValue() << 20;

    if (stringListGiven) {
      options |= STRING_LIST_GIVEN_MASK;
    }

    if (emptyCellsAllowed) {
      options |= EMPTY_CELLS_ALLOWED_MASK;
    }

    if (suppressArrow) {
      options |= SUPPRESS_ARROW_MASK;
    }

    if (showPrompt) {
      options |= SHOW_PROMPT_MASK;
    }

    if (showError) {
      options |= SHOW_ERROR_MASK;
    }

    // The text
    IntegerHelper.getFourBytes(options, data, pos);
    pos += 4;

    IntegerHelper.getTwoBytes(promptTitle.length(), data, pos);
    pos += 2;

    data[pos] = (byte) 0x1; // unicode indicator
    pos++;

    StringHelper.getUnicodeBytes(promptTitle, data, pos);
    pos += promptTitle.length() * 2;

    IntegerHelper.getTwoBytes(errorTitle.length(), data, pos);
    pos += 2;

    data[pos] = (byte) 0x1; // unicode indicator
    pos++;

    StringHelper.getUnicodeBytes(errorTitle, data, pos);
    pos += errorTitle.length() * 2;

    IntegerHelper.getTwoBytes(promptText.length(), data, pos);
    pos += 2;

    data[pos] = (byte) 0x1; // unicode indicator
    pos++;

    StringHelper.getUnicodeBytes(promptText, data, pos);
    pos += promptText.length() * 2;

    IntegerHelper.getTwoBytes(errorText.length(), data, pos);
    pos += 2;

    data[pos] = (byte) 0x1; // unicode indicator
    pos++;

    StringHelper.getUnicodeBytes(errorText, data, pos);
    pos += errorText.length() * 2;

    // Formula 1
    IntegerHelper.getTwoBytes(f1Bytes.length, data, pos);
    pos += 4;

    System.arraycopy(f1Bytes, 0, data, pos, f1Bytes.length);
    pos += f1Bytes.length;

    // Formula 2
    IntegerHelper.getTwoBytes(f2Bytes.length, data, pos);
    pos += 4;

    System.arraycopy(f2Bytes, 0, data, pos, f2Bytes.length);
    pos += f2Bytes.length;

    // The cell ranges
    IntegerHelper.getTwoBytes(1, data, pos);
    pos += 2;

    IntegerHelper.getTwoBytes(row1, data, pos);
    pos += 2;

    IntegerHelper.getTwoBytes(row2, data, pos);
    pos += 2;

    IntegerHelper.getTwoBytes(column1, data, pos);
    pos += 2;

    IntegerHelper.getTwoBytes(column2, data, pos);
    pos += 2;

    return data;
  }
コード例 #9
0
  /** Constructor */
  public DVParser(byte[] data, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws) {
    Assert.verify(nt != null);

    copied = false;
    int options = IntegerHelper.getInt(data[0], data[1], data[2], data[3]);

    int typeVal = options & 0xf;
    type = DVType.getType(typeVal);

    int errorStyleVal = (options & 0x70) >> 4;
    errorStyle = ErrorStyle.getErrorStyle(errorStyleVal);

    int conditionVal = (options & 0xf00000) >> 20;
    condition = Condition.getCondition(conditionVal);

    stringListGiven = (options & STRING_LIST_GIVEN_MASK) != 0;
    emptyCellsAllowed = (options & EMPTY_CELLS_ALLOWED_MASK) != 0;
    suppressArrow = (options & SUPPRESS_ARROW_MASK) != 0;
    showPrompt = (options & SHOW_PROMPT_MASK) != 0;
    showError = (options & SHOW_ERROR_MASK) != 0;

    int pos = 4;
    int length = IntegerHelper.getInt(data[pos], data[pos + 1]);
    if (length > 0 && data[pos + 2] == 0) {
      promptTitle = StringHelper.getString(data, length, pos + 3, ws);
      pos += length + 3;
    } else if (length > 0) {
      promptTitle = StringHelper.getUnicodeString(data, length, pos + 3);
      pos += length * 2 + 3;
    } else {
      pos += 3;
    }

    length = IntegerHelper.getInt(data[pos], data[pos + 1]);
    if (length > 0 && data[pos + 2] == 0) {
      errorTitle = StringHelper.getString(data, length, pos + 3, ws);
      pos += length + 3;
    } else if (length > 0) {
      errorTitle = StringHelper.getUnicodeString(data, length, pos + 3);
      pos += length * 2 + 3;
    } else {
      pos += 3;
    }

    length = IntegerHelper.getInt(data[pos], data[pos + 1]);
    if (length > 0 && data[pos + 2] == 0) {
      promptText = StringHelper.getString(data, length, pos + 3, ws);
      pos += length + 3;
    } else if (length > 0) {
      promptText = StringHelper.getUnicodeString(data, length, pos + 3);
      pos += length * 2 + 3;
    } else {
      pos += 3;
    }

    length = IntegerHelper.getInt(data[pos], data[pos + 1]);
    if (length > 0 && data[pos + 2] == 0) {
      errorText = StringHelper.getString(data, length, pos + 3, ws);
      pos += length + 3;
    } else if (length > 0) {
      errorText = StringHelper.getUnicodeString(data, length, pos + 3);
      pos += length * 2 + 3;
    } else {
      pos += 3;
    }

    int formula1Length = IntegerHelper.getInt(data[pos], data[pos + 1]);
    pos += 4;
    int formula1Pos = pos;
    pos += formula1Length;

    int formula2Length = IntegerHelper.getInt(data[pos], data[pos + 1]);
    pos += 4;
    int formula2Pos = pos;
    pos += formula2Length;

    pos += 2;

    row1 = IntegerHelper.getInt(data[pos], data[pos + 1]);
    pos += 2;

    row2 = IntegerHelper.getInt(data[pos], data[pos + 1]);
    pos += 2;

    column1 = IntegerHelper.getInt(data[pos], data[pos + 1]);
    pos += 2;

    column2 = IntegerHelper.getInt(data[pos], data[pos + 1]);
    pos += 2;

    extendedCellsValidation = (row1 == row2 && column1 == column2) ? false : true;

    // Do the formulas
    try {
      // First, create a temporary  blank cell for any formula relative
      // references
      EmptyCell tmprt = new EmptyCell(column1, row1);

      if (formula1Length != 0) {
        byte[] tokens = new byte[formula1Length];
        System.arraycopy(data, formula1Pos, tokens, 0, formula1Length);
        formula1 = new FormulaParser(tokens, tmprt, es, nt, ws, ParseContext.DATA_VALIDATION);
        formula1.parse();
      }

      if (formula2Length != 0) {
        byte[] tokens = new byte[formula2Length];
        System.arraycopy(data, formula2Pos, tokens, 0, formula2Length);
        formula2 = new FormulaParser(tokens, tmprt, es, nt, ws, ParseContext.DATA_VALIDATION);
        formula2.parse();
      }
    } catch (FormulaException e) {
      logger.warn(
          e.getMessage()
              + " for cells "
              + CellReferenceHelper.getCellReference(column1, row1)
              + "-"
              + CellReferenceHelper.getCellReference(column2, row2));
    }
  }