Package org.apache.poi.hssf.record

Examples of org.apache.poi.hssf.record.Record


  private static void confirmStringRecord(HSSFSheet sheet, boolean isPresent) {
    Record[] recs = RecordInspector.getRecords(sheet, 0);
    assertEquals(isPresent ? 28 : 27, recs.length);
    int index = 22;
    Record fr = recs[index++];
    assertEquals(FormulaRecord.class, fr.getClass());
    if (isPresent) {
      assertEquals(StringRecord.class, recs[index++].getClass());
    } else {
      assertFalse(StringRecord.class == recs[index].getClass());
    }
    Record dbcr = recs[index++];
    assertEquals(DBCellRecord.class, dbcr.getClass());
  }
View Full Code Here


    process:
    try
    {
      byte[] sidbytes  = new byte[ 2 ];
      int    bytesread = in.read(sidbytes);
      Record rec       = null;

      while (bytesread > 0)
      {

        sid = LittleEndian.getShort(sidbytes);
               
                //
                // for some reasons we have to make the workbook to be at least 4096 bytes
                // but if we have such workbook we fill the end of it with zeros (many zeros)
                //
                // it is not good:
                // if the length( all zero records ) % 4 = 1
                // e.g.: any zero record would be readed as  4 bytes at once ( 2 - id and 2 - size ).
                // And the last 1 byte will be readed WRONG ( the id must be 2 bytes )
                //
                // So we should better to check if the sid is zero and not to read more data
                // The zero sid shows us that rest of the stream data is a fake to make workbook
                // certain size
                //
                if ( sid == 0 )
                    break;


        if ((rec != null) && (sid != ContinueRecord.sid))
        {
          userCode = req.processRecord(rec);
          if (userCode != 0) break process;
        }
        if (sid != ContinueRecord.sid)
        {
          short  size = LittleEndian.readShort(in);
          byte[] data = new byte[ size ];

          if (data.length > 0)
          {
            in.read(data);
          }
                                        //System.out.println("creating "+sid);
          Record[] recs = RecordFactory.createRecord(sid, size,
                                 data);

          if (recs.length > 1)
          {                                // we know that the multiple
            for (int k = 0; k < (recs.length - 1); k++)
            {                            // record situations do not
              userCode = req.processRecord(
                recs[ k ]);          // contain continue records
              if (userCode != 0) break process;
            }
          }
          rec = recs[ recs.length - 1 ];   // regardless we'll process

          // the last record as though
          // it might be continued
          // if there is only one
          // records, it will go here too.
        }
        else
        {                                    // we do have a continue record
          short  size = LittleEndian.readShort(in);
          byte[] data = new byte[ size ];

          if (data.length > 0)
          {
            in.read(data);
          }
          rec.processContinueRecord(data);
        }
        bytesread = in.read(sidbytes);       // read next record sid
      }
      if (rec != null)
      {
View Full Code Here

    }
    throw new RuntimeException("Did not find insert point for GUTS");
  }
  private static boolean isPageBreakPriorRecord(Object rb) {
    if (rb instanceof Record) {
      Record record = (Record) rb;
      switch (record.getSid()) {
        case BOFRecord.sid:
        case IndexRecord.sid:
        // calc settings block
          case UncalcedRecord.sid:
          case CalcCountRecord.sid:
View Full Code Here

      }
      if (rb instanceof DataValidityTable) {
        continue;
      }
     
      Record rec = (Record) rb;
      switch (rec.getSid()) {
        case WindowTwoRecord.sid:
        case SCLRecord.sid:
        case PaneRecord.sid:
        case SelectionRecord.sid:
        case UnknownRecord.STANDARDWIDTH_0099:
View Full Code Here

      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:
View Full Code Here

    }
    while (i > 0) {
      i--;
      RecordBase rb = records.get(i);
      if (isDVTPriorRecord(rb)) {
        Record nextRec = (Record) records.get(i + 1);
        if (!isDVTSubsequentRecord(nextRec.getSid())) {
          throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName()
              + ") found after (" + rb.getClass().getName() + ")");
        }
        return i+1;
      }
      Record rec = (Record) rb;
      if (!isDVTSubsequentRecord(rec.getSid())) {
        throw new IllegalStateException("Unexpected (" + rec.getClass().getName()
            + ") while looking for DV Table insert pos");
      }
    }
    return 0;
  }
View Full Code Here

    throw new RuntimeException("Did not find insert point for GUTS");
  }

  private static boolean isGutsPriorRecord(RecordBase rb) {
    if (rb instanceof Record) {
      Record record = (Record) rb;
      switch (record.getSid()) {
        case BOFRecord.sid:
        case IndexRecord.sid:
        // calc settings block
          case UncalcedRecord.sid:
          case CalcCountRecord.sid:
View Full Code Here

        List<Record> records = new ArrayList<Record>(recs.size() / 3);
        retval.records.setRecords(records);

        int k;
        for (k = 0; k < recs.size(); k++) {
            Record rec = recs.get(k);

            if (rec.getSid() == EOFRecord.sid) {
                records.add(rec);
                if (log.check( POILogger.DEBUG ))
                    log.log(DEBUG, "found workbook eof record at " + k);
                break;
            }
            switch (rec.getSid()) {

                case BoundSheetRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found boundsheet record at " + k);
                    retval.boundsheets.add((BoundSheetRecord) rec);
                    retval.records.setBspos( k );
                    break;

                case SSTRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found sst record at " + k);
                    retval.sst = ( SSTRecord ) rec;
                    break;

                case FontRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found font record at " + k);
                    retval.records.setFontpos( k );
                    retval.numfonts++;
                    break;

                case ExtendedFormatRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found XF record at " + k);
                    retval.records.setXfpos( k );
                    retval.numxfs++;
                    break;

                case TabIdRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found tabid record at " + k);
                    retval.records.setTabpos( k );
                    break;

                case ProtectRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found protect record at " + k);
                    retval.records.setProtpos( k );
                    break;

                case BackupRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found backup record at " + k);
                    retval.records.setBackuppos( k );
                    break;
                case ExternSheetRecord.sid :
                    throw new RuntimeException("Extern sheet is part of LinkTable");
                case NameRecord.sid :
                case SupBookRecord.sid :
                    // LinkTable can start with either of these
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found SupBook record at " + k);
                    retval.linkTable = new LinkTable(recs, k, retval.records);
                    k+=retval.linkTable.getRecordCount() - 1;
                    continue;
                case FormatRecord.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found format record at " + k);
                    retval.formats.add((FormatRecord) rec);
                    retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).getIndexCode() ? retval.maxformatid : ((FormatRecord)rec).getIndexCode();
                    break;
                case DateWindow1904Record.sid :
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found datewindow1904 record at " + k);
                    retval.uses1904datewindowing = ((DateWindow1904Record)rec).getWindowing() == 1;
                    break;
                case PaletteRecord.sid:
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found palette record at " + k);
                    retval.records.setPalettepos( k );
                    break;
                case WindowOneRecord.sid:
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found WindowOneRecord at " + k);
                    retval.windowOne = (WindowOneRecord) rec;
                    break;
                case WriteAccessRecord.sid:
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found WriteAccess at " + k);
                    retval.writeAccess = (WriteAccessRecord) rec;
                    break;
                case WriteProtectRecord.sid:
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found WriteProtect at " + k);
                    retval.writeProtect = (WriteProtectRecord) rec;
                    break;
                case FileSharingRecord.sid:
                    if (log.check( POILogger.DEBUG ))
                        log.log(DEBUG, "found FileSharing at " + k);
                    retval.fileShare = (FileSharingRecord) rec;
                default :
            }
            records.add(rec);
        }
        //What if we dont have any ranges and supbooks
        //        if (retval.records.supbookpos == 0) {
        //            retval.records.supbookpos = retval.records.bspos + 1;
        //            retval.records.namepos    = retval.records.supbookpos + 1;
        //        }
       
        // Look for other interesting values that
        //  follow the EOFRecord
        for ( ; k < recs.size(); k++) {
            Record rec = recs.get(k);
            switch (rec.getSid()) {
                case HyperlinkRecord.sid:
                    retval.hyperlinks.add((HyperlinkRecord)rec);
                    break;
            }
        }
View Full Code Here

     */
    public StyleRecord getStyleRecord(int xfIndex) {
        // Style records always follow after
        //  the ExtendedFormat records
        for(int i=records.getXfpos(); i<records.size(); i++) {
            Record r = records.get(i);
            if(r instanceof ExtendedFormatRecord) {
                continue;
            }
            if(!(r instanceof StyleRecord)) {
                return null;
View Full Code Here

       
        // Find the spot
        int addAt = -1;
        for(int i=records.getXfpos(); i<records.size() &&
                addAt == -1; i++) {
            Record r = records.get(i);
            if(r instanceof ExtendedFormatRecord ||
                    r instanceof StyleRecord) {
                // Keep going
            } else {
                addAt = i;
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.Record

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.