org.apache.poi.hssf.record.Record.getSid()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(247)

本文整理了Java中org.apache.poi.hssf.record.Record.getSid方法的一些代码示例,展示了Record.getSid的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Record.getSid方法的具体详情如下:
包路径:org.apache.poi.hssf.record.Record
类名称:Record
方法名:getSid

Record.getSid介绍

[英]return the non static version of the id for this record.
[中]返回此记录的id的非静态版本。

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * These records may occur between the 'Worksheet Protection Block' and DIMENSION:
 * <pre>
 * o DEFCOLWIDTH
 * oo COLINFO
 * o SORT
 * </pre>
 */
private static boolean isProtectionSubsequentRecord(Object rb) {
  if (rb instanceof ColumnInfoRecordsAggregate) {
    return true; // oo COLINFO
  }
  if (rb instanceof Record) {
    Record record = (Record) rb;
    switch (record.getSid()) {
      case DefaultColWidthRecord.sid:
      case UnknownRecord.SORT_0090:
        return true;
    }
  }
  return false;
}

代码示例来源:origin: org.apache.poi/poi

private static boolean isDVTPriorRecord(RecordBase rb) {
  if (rb instanceof MergedCellsTable || rb instanceof ConditionalFormattingTable) {
    return true;
  }
  short sid = ((Record)rb).getSid();
  switch(sid) {
    case WindowTwoRecord.sid:
    case UnknownRecord.SCL_00A0:
    case PaneRecord.sid:
    case SelectionRecord.sid:
    case UnknownRecord.STANDARDWIDTH_0099:
    // MergedCellsTable
    case UnknownRecord.LABELRANGES_015F:
    case UnknownRecord.PHONETICPR_00EF:
    // ConditionalFormattingTable
    case HyperlinkRecord.sid:
    case UnknownRecord.QUICKTIP_0800:
    // name of a VBA module    
    case UnknownRecord.CODENAME_1BA:
      return true;
  }
  return false;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * @param records list of records to look into
 * @param loc - location of the record which sid must be returned
 * @return sid of the record with selected location
 */
private static short sid(List<RecordBase> records, int loc) {
  RecordBase record = records.get(loc);
  if (record instanceof Record) {
    return ((Record)record).getSid();
  } else {
    // Aggregates don't have a sid
    // We could step into them, but for these needs we don't care
    return -1;
  }
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Finds the first occurrence of a record matching a particular sid and
 * returns it's position.
 * @param sid   the sid to search for
 * @return  the record position of the matching record or -1 if no match
 *          is made.
 */
public int findFirstRecordLocBySid( short sid ) { // TODO - remove this method
  int max = _records.size();
  for (int i=0; i< max; i++) {
    Object rb = _records.get(i);
    if (!(rb instanceof Record)) {
      continue;
    }
    Record record = (Record) rb;
    if (record.getSid() == sid) {
      return i;
    }
  }
  return -1;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * @return -1 if at end of records
 */
public int peekNextSid() {
  if(!hasNext()) {
    return -1;
  }
  return _list.get(_nextIndex).getSid();
}

代码示例来源:origin: org.apache.poi/poi

private void checkNotPresent(Record rec) {
  if (rec != null) {
    throw new org.apache.poi.util.RecordFormatException("Duplicate PageSettingsBlock record (sid=0x"
        + Integer.toHexString(rec.getSid()) + ")");
  }
}

代码示例来源:origin: org.apache.poi/poi

private void checkNotPresent(Record rec) {
  if (rec != null) {
    throw new RecordFormatException("Duplicate PageSettingsBlock record (sid=0x"
        + Integer.toHexString(rec.getSid()) + ")");
  }
}

代码示例来源:origin: org.apache.poi/poi

/**
 * copied from Workbook
 */
private int findFirstRecordLocBySid(short sid) {
  int index = 0;
  for (Record record : _workbookRecordList.getRecords()) {
    if (record.getSid() == sid) {
      return index;
    }
    index++;
  }
  return -1;
}

代码示例来源:origin: org.apache.poi/poi

private static int findInsertPosForNewMergedRecordTable(List<RecordBase> records) {
  for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
    Object rb = records.get(i);
    if (!(rb instanceof Record)) {
      // DataValidityTable, ConditionalFormattingTable,
      // even PageSettingsBlock (which doesn't normally appear after 'View Settings')
      continue;
    }
    Record rec = (Record) rb;
    switch (rec.getSid()) {
      // 'View Settings' (4 records)
      case WindowTwoRecord.sid:
      case SCLRecord.sid:
      case PaneRecord.sid:
      case SelectionRecord.sid:
      case UnknownRecord.STANDARDWIDTH_0099:
        return i + 1;
    }
  }
  throw new RuntimeException("Did not find Window2 record");
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Returns the first occurance of a record matching a particular sid.
 *
 * @param sid the sid
 *
 * @return the matching record or {@code null} if it wasn't found
 */
public Record findFirstRecordBySid(short sid) {
  for (Record record : records.getRecords() ) {
    if (record.getSid() == sid) {
      return record;
    }
  }
  return null;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Returns the index of a record matching a particular sid.
 * @param sid   The sid of the record to match
 * @return      The index of -1 if no match made.
 */
public int findFirstRecordLocBySid(short sid) {
  int index = 0;
  for (Record record : records.getRecords() ) {
    if (record.getSid() == sid) {
      return index;
    }
    index ++;
  }
  return -1;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Returns the next occurance of a record matching a particular sid.
 *
 * @param sid the sid
 * @param pos specifies the n-th matching sid
 *
 * @return the matching record or {@code null} if it wasn't found
 */
public Record findNextRecordBySid(short sid, int pos) {
  int matches = 0;
  for (Record record : records.getRecords() ) {
    if (record.getSid() == sid && matches++ == pos) {
      return record;
    }
  }
  return null;
}

代码示例来源:origin: org.apache.poi/poi

/**
 * used internally -- given a cell value record, figure out its type
 */
private static CellType determineType(CellValueRecordInterface cval) {
  if (cval instanceof FormulaRecordAggregate) {
    return CellType.FORMULA;
  }
  // all others are plain BIFF records
  Record record = ( Record ) cval;
  switch (record.getSid()) {
    case NumberRecord.sid :   return CellType.NUMERIC;
    case BlankRecord.sid :    return CellType.BLANK;
    case LabelSSTRecord.sid : return CellType.STRING;
    case BoolErrRecord.sid :
      BoolErrRecord boolErrRecord = ( BoolErrRecord ) record;
      return boolErrRecord.isBoolean()
           ? CellType.BOOLEAN
           : CellType.ERROR;
  }
  throw new RuntimeException("Bad cell value rec (" + cval.getClass().getName() + ")");
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Create CFRecordsAggregate from a list of CF Records
 * @param rs - the stream to read from
 * @return CFRecordsAggregate object
 */
public static CFRecordsAggregate createCFAggregate(RecordStream rs) {
  Record rec = rs.getNext();
  if (rec.getSid() != CFHeaderRecord.sid &&
    rec.getSid() != CFHeader12Record.sid) {
    throw new IllegalStateException("next record sid was " + rec.getSid() 
        + " instead of " + CFHeaderRecord.sid + " or " +
        CFHeader12Record.sid + " as expected");
  }
  CFHeaderBase header = (CFHeaderBase)rec;
  int nRules = header.getNumberOfConditionalFormats();
  CFRuleBase[] rules = new CFRuleBase[nRules];
  for (int i = 0; i < rules.length; i++) {
    rules[i] = (CFRuleBase) rs.getNext();
  }
  return new CFRecordsAggregate(header, rules);
}

代码示例来源:origin: org.apache.poi/poi

@Override
  public void visitRecord(Record r) {
    if (r.getSid() == UserSViewBegin.sid) {
      String guid = HexDump.toHex(((UserSViewBegin) r).getGuid());
      HeaderFooterRecord hf = hfGuidMap.get(guid);
      if (hf != null) {
        cv.append(hf);
        _sviewHeaderFooters.remove(hf);
      }
    }
  }
});

代码示例来源:origin: org.apache.poi/poi

/**
 * sends the record event to all registered listeners.
 * @param record the record to be thrown.
 * @return <code>false</code> to abort.  This aborts
 * out of the event loop should the listener return false
 */
private boolean processRecord(Record record) {
  if (!isSidIncluded(record.getSid())) {
    return true;
  }
  return _listener.processRecord(record);
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Creates a FormatRecord, inserts it, and returns the index code.
 * @param formatString the format string
 * @return the index code of the format record.
 * @see org.apache.poi.hssf.record.FormatRecord
 * @see org.apache.poi.hssf.record.Record
 */
public int createFormat(String formatString) {
  maxformatid = maxformatid >= 0xa4 ? maxformatid + 1 : 0xa4; //Starting value from M$ empircal study.
  FormatRecord rec = new FormatRecord(maxformatid, formatString);
  int pos = 0;
  while ( pos < records.size() && records.get( pos ).getSid() != FormatRecord.sid ) {
    pos++;
  }
  pos += formats.size();
  formats.add( rec );
  records.add( pos, rec );
  return maxformatid;
}

代码示例来源:origin: org.apache.poi/poi

public int getSize() {
  int retval = 0;
  SSTRecord lSST = null;
  for ( Record record : records.getRecords() ) {
    if (record instanceof SSTRecord) {
      lSST = (SSTRecord)record;
    }
    if (record.getSid() == ExtSSTRecord.sid && lSST != null) {
      retval += lSST.calcExtSSTRecordSize();
    } else {
      retval += record.getRecordSize();
    }
  }
  return retval;
}

代码示例来源:origin: org.apache.poi/poi

public CustomViewSettingsRecordAggregate(RecordStream rs) {
  _begin = rs.getNext();
  if (_begin.getSid() != UserSViewBegin.sid) {
    throw new IllegalStateException("Bad begin record");
  }
  List<RecordBase> temp = new ArrayList<>();
  while (rs.peekNextSid() != UserSViewEnd.sid) {
    if (PageSettingsBlock.isComponentRecord(rs.peekNextSid())) {
      if (_psBlock != null) {
        if (rs.peekNextSid() == HeaderFooterRecord.sid) {
          // test samples: 45538_classic_Footer.xls, 45538_classic_Header.xls
          _psBlock.addLateHeaderFooter((HeaderFooterRecord)rs.getNext());
          continue;
        }
        throw new IllegalStateException(
            "Found more than one PageSettingsBlock in chart sub-stream, had sid: " + rs.peekNextSid());
      }
      _psBlock = new PageSettingsBlock(rs);
      temp.add(_psBlock);
      continue;
    }
    temp.add(rs.getNext());
  }
  _recs = temp;
  _end = rs.getNext(); // no need to save EOF in field
  if (_end.getSid() != UserSViewEnd.sid) {
    throw new IllegalStateException("Bad custom view settings end record");
  }
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Method run
 * 
 * @throws IOException if the file contained errors 
 */
public void run() throws IOException {
  POIFSFileSystem fs  = new POIFSFileSystem(new File(file), true);
  try {
    InputStream is = BiffViewer.getPOIFSInputStream(fs);
    try {
      List<Record> records = RecordFactory.createRecords(is);
      for (Record record : records) {
        if (record.getSid() == FormulaRecord.sid) {
          if (list) {
            listFormula((FormulaRecord) record);
          } else {
            parseFormulaRecord((FormulaRecord) record);
          }
        }
      }
    } finally {
      is.close();
    }
  } finally {
    fs.close();
  }
}

相关文章

微信公众号

最新文章

更多