/**
   * 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;
  }
  /** 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;
  }