Пример #1
0
  /**
   * Constructs this object from the raw data. Used when reading in a format record
   *
   * @param t the raw data
   * @param ws the workbook settings
   */
  public FontRecord(Record t, WorkbookSettings ws) {
    super(t);

    byte[] data = getRecord().getData();

    pointHeight = IntegerHelper.getInt(data[0], data[1]) / EXCEL_UNITS_PER_POINT;
    colourIndex = IntegerHelper.getInt(data[4], data[5]);
    boldWeight = IntegerHelper.getInt(data[6], data[7]);
    scriptStyle = IntegerHelper.getInt(data[8], data[9]);
    underlineStyle = data[10];
    fontFamily = data[11];
    characterSet = data[12];
    initialized = false;

    if ((data[2] & 0x02) != 0) {
      italic = true;
    }

    if ((data[2] & 0x08) != 0) {
      struckout = true;
    }

    int numChars = data[14];
    if (data[15] == 0) {
      name = StringHelper.getString(data, numChars, 16, ws);
    } else if (data[15] == 1) {
      name = StringHelper.getUnicodeString(data, numChars, 16);
    } else {
      // Some font names don't have the unicode indicator
      name = StringHelper.getString(data, numChars, 15, ws);
    }
  }
Пример #2
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));
    }
  }