コード例 #1
0
  public IndexRecord(RecordInputStream in) {
    int field_1_zero = in.readInt();
    if (field_1_zero != 0) {
      throw new RecordFormatException("Expected zero for field 1 but got " + field_1_zero);
    }
    field_2_first_row = in.readInt();
    field_3_last_row_add1 = in.readInt();
    field_4_zero = in.readInt();

    int nCells = in.remaining() / 4;
    field_5_dbcells = new IntList(nCells);
    for (int i = 0; i < nCells; i++) {
      field_5_dbcells.add(in.readInt());
    }
  }
コード例 #2
0
  public TextObjectRecord(RecordInputStream in) {
    field_1_options = in.readUShort();
    field_2_textOrientation = in.readUShort();
    field_3_reserved4 = in.readUShort();
    field_4_reserved5 = in.readUShort();
    field_5_reserved6 = in.readUShort();
    int field_6_textLength = in.readUShort();
    int field_7_formattingDataLength = in.readUShort();
    field_8_reserved7 = in.readInt();

    if (in.remaining() > 0) {
      // Text Objects can have simple reference formulas
      // (This bit not mentioned in the MS document)
      if (in.remaining() < 11) {
        throw new RecordFormatException("Not enough remaining data for a link formula");
      }
      int formulaSize = in.readUShort();
      _unknownPreFormulaInt = in.readInt();
      Ptg[] ptgs = Ptg.readTokens(formulaSize, in);
      if (ptgs.length != 1) {
        throw new RecordFormatException("Read " + ptgs.length + " tokens but expected exactly 1");
      }
      _linkRefPtg = (OperandPtg) ptgs[0];
      if (in.remaining() > 0) {
        _unknownPostFormulaByte = Byte.valueOf(in.readByte());
      } else {
        _unknownPostFormulaByte = null;
      }
    } else {
      _linkRefPtg = null;
    }
    if (in.remaining() > 0) {
      throw new RecordFormatException("Unused " + in.remaining() + " bytes at end of record");
    }

    String text;
    if (field_6_textLength > 0) {
      text = readRawString(in, field_6_textLength);
    } else {
      text = "";
    }
    _text = new HSSFRichTextString(text);

    if (field_7_formattingDataLength > 0) {
      processFontRuns(in, _text, field_7_formattingDataLength);
    }
  }
コード例 #3
0
 public ArrayRecord(RecordInputStream in) {
   super(in);
   _options = in.readUShort();
   _field3notUsed = in.readInt();
   int formulaTokenLen = in.readUShort();
   int totalFormulaLen = in.available();
   _formula = Formula.read(formulaTokenLen, in, totalFormulaLen);
 }
コード例 #4
0
  public BOFRecord(RecordInputStream in) {
    field_1_version = in.readShort();
    field_2_type = in.readShort();

    // Some external tools don't generate all of
    //  the remaining fields
    if (in.remaining() >= 2) {
      field_3_build = in.readShort();
    }
    if (in.remaining() >= 2) {
      field_4_year = in.readShort();
    }
    if (in.remaining() >= 4) {
      field_5_history = in.readInt();
    }
    if (in.remaining() >= 4) {
      field_6_rversion = in.readInt();
    }
  }
コード例 #5
0
 private static void processFontRuns(
     RecordInputStream in, HSSFRichTextString str, int formattingRunDataLength) {
   if (formattingRunDataLength % FORMAT_RUN_ENCODED_SIZE != 0) {
     throw new RecordFormatException(
         "Bad format run data length " + formattingRunDataLength + ")");
   }
   int nRuns = formattingRunDataLength / FORMAT_RUN_ENCODED_SIZE;
   for (int i = 0; i < nRuns; i++) {
     short index = in.readShort();
     short iFont = in.readShort();
     in.readInt(); // skip reserved.
     str.applyFont(index, str.length(), iFont);
   }
 }
コード例 #6
0
  public HyperlinkRecord(RecordInputStream in) {
    _range = new CellRangeAddress(in);

    _guid = new GUID(in);

    /**
     * streamVersion (4 bytes): An unsigned integer that specifies the version number of the
     * serialization implementation used to save this structure. This value MUST equal 2.
     */
    int streamVersion = in.readInt();
    if (streamVersion != 0x00000002) {
      throw new RecordFormatException("Stream Version must be 0x2 but found " + streamVersion);
    }
    _linkOpts = in.readInt();

    if ((_linkOpts & HLINK_LABEL) != 0) {
      int label_len = in.readInt();
      _label = in.readUnicodeLEString(label_len);
    }

    if ((_linkOpts & HLINK_TARGET_FRAME) != 0) {
      int len = in.readInt();
      _targetFrame = in.readUnicodeLEString(len);
    }

    if ((_linkOpts & HLINK_URL) != 0 && (_linkOpts & HLINK_UNC_PATH) != 0) {
      _moniker = null;
      int nChars = in.readInt();
      _address = in.readUnicodeLEString(nChars);
    }

    if ((_linkOpts & HLINK_URL) != 0 && (_linkOpts & HLINK_UNC_PATH) == 0) {
      _moniker = new GUID(in);

      if (URL_MONIKER.equals(_moniker)) {
        int length = in.readInt();
        /**
         * The value of <code>length<code> be either the byte size of the url field
         * (including the terminating NULL character) or the byte size of the url field plus 24.
         * If the value of this field is set to the byte size of the url field,
         * then the tail bytes fields are not present.
         */
        int remaining = in.remaining();
        if (length == remaining) {
          int nChars = length / 2;
          _address = in.readUnicodeLEString(nChars);
        } else {
          int nChars = (length - TAIL_SIZE) / 2;
          _address = in.readUnicodeLEString(nChars);
          /**
           * TODO: make sense of the remaining bytes According to the spec they consist of: 1.
           * 16-byte GUID: This field MUST equal {0xF4815879, 0x1D3B, 0x487F, 0xAF, 0x2C, 0x82,
           * 0x5D, 0xC4, 0x85, 0x27, 0x63} 2. Serial version, this field MUST equal 0 if present. 3.
           * URI Flags
           */
          _uninterpretedTail = readTail(URL_TAIL, in);
        }
      } else if (FILE_MONIKER.equals(_moniker)) {
        _fileOpts = in.readShort();

        int len = in.readInt();
        _shortFilename = StringUtil.readCompressedUnicode(in, len);
        _uninterpretedTail = readTail(FILE_TAIL, in);
        int size = in.readInt();
        if (size > 0) {
          int charDataSize = in.readInt();

          // From the spec: An optional unsigned integer that MUST be 3 if present
          // but some files has 4
          int usKeyValue = in.readUShort();

          _address = StringUtil.readUnicodeLE(in, charDataSize / 2);
        } else {
          _address = null;
        }
      } else if (STD_MONIKER.equals(_moniker)) {
        _fileOpts = in.readShort();

        int len = in.readInt();

        byte[] path_bytes = new byte[len];
        in.readFully(path_bytes);

        _address = new String(path_bytes);
      }
    }

    if ((_linkOpts & HLINK_PLACE) != 0) {

      int len = in.readInt();
      _textMark = in.readUnicodeLEString(len);
    }

    if (in.remaining() > 0) {
      logger.log(
          POILogger.WARN,
          "Hyperlink data remains: " + in.remaining() + " : " + HexDump.toHex(in.readRemainder()));
    }
  }