public CustomViewSettingsRecordAggregate(RecordStream rs)
 {
     _begin = rs.GetNext();
     if (_begin.Sid != UserSViewBegin.sid)
     {
         throw new InvalidOperationException("Bad begin record");
     }
     List<RecordBase> temp = new List<RecordBase>();
     while (rs.PeekNextSid() != UserSViewEnd.sid)
     {
         if (PageSettingsBlock.IsComponentRecord(rs.PeekNextSid()))
         {
             if (_psBlock != null)
             {
                 throw new InvalidOperationException(
                         "Found more than one PageSettingsBlock in custom view Settings sub-stream");
             }
             _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.Sid != UserSViewEnd.sid)
     {
         throw new InvalidOperationException("Bad custom view Settings end record");
     }
 }
        /**
         * Process this record ourselves, and then
         *  pass it on to our child listener
         */
        public void ProcessRecord(Record record)
        {
            // Handle it ourselves
            ProcessRecordInternally(record);

            // Now pass on to our child
            childListener.ProcessRecord(record);
        }
Exemplo n.º 3
0
    /**
 * sends the record event to all registered listeners.
 * @param record the record to be thrown.
 * @return <c>false</c> to abort.  This aborts
 * out of the event loop should the listener return false
 */
    private bool ProcessRecord(Record record)
    {
        if (!IsSidIncluded(record.Sid))
        {
            return true;
        }
        return _listener.ProcessRecord(record);
    }
 /**
  * Process the record ourselves, but do not
  *  pass it on to the child Listener.
  * @param record
  */
 public void ProcessRecordInternally(Record record)
 {
     if (record is FormatRecord)
     {
         FormatRecord fr = (FormatRecord)record;
         customFormatRecords[fr.IndexCode] = fr;
     }
     else if (record is ExtendedFormatRecord)
     {
         ExtendedFormatRecord xr = (ExtendedFormatRecord)record;
         xfRecords.Add(xr);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds the specified pos.
 /// </summary>
 /// <param name="pos">The pos.</param>
 /// <param name="r">The r.</param>
 public void Add(int pos, Record r)
 {
     records.Insert(pos, r);
     if (Protpos >= pos) Protpos=(protpos + 1);
     if (Bspos >= pos) Bspos=(bspos + 1);
     if (Tabpos >= pos) Tabpos=(tabpos + 1);
     if (Fontpos >= pos) Fontpos=(fontpos + 1);
     if (Xfpos >= pos) Xfpos=(xfpos + 1);
     if (Backuppos >= pos) Backuppos=(backuppos + 1);
     if (Namepos>= pos) Namepos=(namepos + 1);
     if (Supbookpos >= pos) Supbookpos=(supbookpos + 1);
     if ((Palettepos!= -1) && (Palettepos>= pos)) Palettepos=(palettepos + 1);
     if (ExternsheetPos >= pos) ExternsheetPos=ExternsheetPos + 1;
 }
Exemplo n.º 6
0
 /**
   * Process an HSSF Record. Called when a record occurs in an HSSF file. 
   * Provides two options for halting the Processing of the HSSF file.
   *
   * The return value provides a means of non-error termination with a 
   * user-defined result code. A value of zero must be returned to 
   * continue Processing, any other value will halt Processing by
   * <c>HSSFEventFactory</c> with the code being passed back by 
   * its abortable Process events methods.
   * 
   * Error termination can be done by throwing the HSSFUserException.
   *
   * Note that HSSFEventFactory will not call the inherited Process 
   *
   * @return result code of zero for continued Processing.
   *
   * @throws HSSFUserException User code can throw this to abort 
   * file Processing by HSSFEventFactory and return diagnostic information.
   */
 public abstract short AbortableProcessRecord(Record record);
Exemplo n.º 7
0
        /**
         * This method, inherited from HSSFListener Is implemented as a stub.
         * It Is never called by HSSFEventFActory or HSSFRequest.
         *
         */

        public virtual void ProcessRecord(Record record)
        {
        }
Exemplo n.º 8
0
 private static void AddAll(List<Record> destList, Record[] srcRecs)
 {
     for (int i = 0; i < srcRecs.Length; i++)
     {
         destList.Add(srcRecs[i]);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Returns the next available record, or null if
        /// this pass didn't return a record that's
        /// suitable for returning (eg was a continue record).
        /// </summary>
        /// <returns></returns>
        private Record GetNextRecord()
        {
            Record toReturn = null;

            if (in1.HasNextRecord)
            {
                // Grab our next record
                in1.NextRecord();
                short sid = in1.Sid;

                //
                // 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)
                    return null;


                // If we had a last record, and this one
                //  Isn't a continue record, then pass
                //  it on to the listener
                if ((rec != null) && (sid != ContinueRecord.sid))
                {
                    // This last record ought to be returned
                    toReturn = rec;
                }

                // If this record Isn't a continue record,
                //  then build it up
                if (sid != ContinueRecord.sid)
                {
                    //Console.WriteLine("creating "+sid);
                    Record[] recs = RecordFactory.CreateRecord(in1);

                    // We know that the multiple record situations
                    //  don't contain continue records, so just
                    //  pass those on to the listener now
                    if (recs.Length > 1)
                    {
                        bonusRecords = new ArrayList(recs.Length - 1);
                        for (int k = 0; k < (recs.Length - 1); k++)
                        {
                            bonusRecords.Add(recs[k]);
                        }
                    }

                    // Regardless of the number we Created, always hold
                    //  onto the last record to be Processed on the next
                    //  loop, in case it has any continue records
                    rec = recs[recs.Length - 1];
                    // Don't return it just yet though, as we probably have
                    //  a record from the last round to return
                }
                else
                {
                    // Normally, ContinueRecords are handled internally
                    // However, in a few cases, there Is a gap between a record at
                    //  its Continue, so we have to handle them specially
                    // This logic Is much like in RecordFactory.CreateRecords()
                    Record[] recs = RecordFactory.CreateRecord(in1);
                    ContinueRecord crec = (ContinueRecord)recs[0];
                    if ((lastRec is ObjRecord) || (lastRec is TextObjectRecord))
                    {
                        // You can have Obj records between a DrawingRecord
                        //  and its continue!
                        lastDrawingRecord.ProcessContinueRecord(crec.Data);
                        // Trigger them on the drawing record, now it's complete
                        rec = lastDrawingRecord;
                    }
                    else if ((lastRec is DrawingGroupRecord))
                    {
                        ((DrawingGroupRecord)lastRec).ProcessContinueRecord(crec.Data);
                        // Trigger them on the drawing record, now it's complete
                        rec = lastRec;
                    }
                    else
                    {
                        if (rec is UnknownRecord)
                        {
                            ;//silently skip records we don't know about
                        }
                        else
                        {
                            throw new RecordFormatException("Records should handle ContinueRecord internally. Should not see this exception");
                        }
                    }
                }

                // Update our tracking of the last record
                lastRec = rec;
                if (rec is DrawingRecord)
                {
                    lastDrawingRecord = (DrawingRecord)rec;
                }
            }
            else
            {
                // No more records
                hitEOS = true;
            }

            // If we've hit the end-of-stream, then
            //  finish off the last record and be done
            if (hitEOS)
            {
                complete = true;

                // Return the last record if there was
                //  one, otherwise null
                if (rec != null)
                {
                    toReturn = rec;
                    rec = null;
                }
            }

            return toReturn;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Removes the specified record.
 /// </summary>
 /// <param name="record">The record.</param>
 public void Remove(Record record)
 {
     int i = records.IndexOf(record);
     this.Remove(i);
 }
Exemplo n.º 11
0
 public void VisitRecord(Record r)
 {
     _list.Add(r);
     _totalSize += r.RecordSize;
 }
Exemplo n.º 12
0
 /**
  * Associates an escher record to an OBJ record or a TXO record.
  */
 public Object AssoicateShapeToObjRecord(EscherRecord r, Record objRecord)
 {
     return shapeToObj[r]= objRecord;
 }
Exemplo n.º 13
0
 public void VisitRecord(Record r)
 {
     _position += r.RecordSize;
     _rv.VisitRecord(r);
 }
Exemplo n.º 14
0
 public void VisitRecord(Record r)
 {
     _totalSize += r.RecordSize;
 }
 private void CheckNotPresent(Record rec)
 {
     if (rec != null)
     {
         throw new RecordFormatException("Duplicate WorksheetProtectionBlock record (sid=0x"
                 + StringUtil.ToHexString(rec.Sid) + ")");
     }
 }
 private static void VisitIfPresent(Record r, RecordVisitor rv)
 {
     if (r != null)
     {
         rv.VisitRecord(r);
     }
 }
Exemplo n.º 17
0
 public void VisitRecord(Record r) {
     _records.Add(r);
 }
Exemplo n.º 18
0
 public void VisitRecord(Record r)
 {
     _destList.Add(r.Clone());
 }
Exemplo n.º 19
0
 public void VisitRecord(Record r)
 {
     int currentOffset = _startOffset + _countBytesWritten;
     _countBytesWritten += r.Serialize(currentOffset, _data);
 }
            /// <summary>
            /// Process an HSSF Record. Called when a record occurs in an HSSF file.
            /// </summary>
            /// <param name="record"></param>
            public void ProcessRecord(Record record)
            {
                String thisText = null;
                int thisRow = -1;

                switch (record.Sid)
                {
                    case BoundSheetRecord.sid:
                        BoundSheetRecord sr = (BoundSheetRecord)record;
                        sheetNames.Add(sr.Sheetname);
                        break;
                    case BOFRecord.sid:
                        BOFRecord bof = (BOFRecord)record;
                        if (bof.Type == BOFRecord.TYPE_WORKSHEET)
                        {
                            sheetNum++;
                            rowNum = -1;

                            if (includeSheetNames)
                            {
                                if (text.Length > 0) text.Append("\n");
                                text.Append(sheetNames[sheetNum]);
                            }
                        }
                        break;
                    case SSTRecord.sid:
                        sstRecord = (SSTRecord)record;
                        break;

                    case FormulaRecord.sid:
                        FormulaRecord frec = (FormulaRecord)record;
                        thisRow = frec.Row;

                        if (formulasNotResults)
                        {
                            thisText = HSSFFormulaParser.ToFormulaString((HSSFWorkbook)null, frec.ParsedExpression);
                        }
                        else
                        {
                            if (frec.HasCachedResultString)
                            {
                                // Formula result is a string
                                // This is stored in the next record
                                outputNextStringValue = true;
                                nextRow = frec.Row;
                            }
                            else
                            {
                                thisText = FormatNumberDateCell(frec, frec.Value);
                            }
                        }
                        break;
                    case StringRecord.sid:
                        if (outputNextStringValue)
                        {
                            // String for formula
                            StringRecord srec = (StringRecord)record;
                            thisText = srec.String;
                            thisRow = nextRow;
                            outputNextStringValue = false;
                        }
                        break;
                    case LabelRecord.sid:
                        LabelRecord lrec = (LabelRecord)record;
                        thisRow = lrec.Row;
                        thisText = lrec.Value;
                        break;
                    case LabelSSTRecord.sid:
                        LabelSSTRecord lsrec = (LabelSSTRecord)record;
                        thisRow = lsrec.Row;
                        if (sstRecord == null)
                        {
                            throw new Exception("No SST record found");
                        }
                        thisText = sstRecord.GetString(lsrec.SSTIndex).ToString();
                        break;
                    case NoteRecord.sid:
                        NoteRecord nrec = (NoteRecord)record;
                        thisRow = nrec.Row;
                        // TODO: Find object to match nrec.GetShapeId()
                        break;
                    case NumberRecord.sid:
                        NumberRecord numrec = (NumberRecord)record;
                        thisRow = numrec.Row;
                        thisText = FormatNumberDateCell(numrec, numrec.Value);
                        break;
                    default:
                        break;
                }

                if (thisText != null)
                {
                    if (thisRow != rowNum)
                    {
                        rowNum = thisRow;
                        if (text.Length > 0)
                            text.Append("\n");
                    }
                    else
                    {
                        text.Append("\t");
                    }
                    text.Append(thisText);
                }
            }
Exemplo n.º 21
0
        /// <summary>
        /// Called by HSSFEventFactory, passes the Record to each listener associated with
        /// a record.sid.
        /// Exception and return value Added 2002-04-19 by Carey Sublette
        /// </summary>
        /// <param name="rec">The record.</param>
        /// <returns>numeric user-specified result code. If zero continue Processing.</returns>
        public short ProcessRecord(Record rec)
        {
            Object obj = records[rec.Sid];
            short userCode = 0;

            if (obj != null)
            {
                IList listeners = (IList)obj;

                for (int k = 0; k < listeners.Count; k++)
                {
                    Object listenObj = listeners[k];
                    if (listenObj is AbortableHSSFListener)
                    {
                        AbortableHSSFListener listener = (AbortableHSSFListener)listenObj;
                        userCode = listener.AbortableProcessRecord(rec);
                        if (userCode != 0) break;
                    }
                    else
                    {
                        HSSFListener listener = (HSSFListener)listenObj;
                        listener.ProcessRecord(rec);
                    }
                }
            }
            return userCode;
        }
Exemplo n.º 22
0
 /// <summary>
 /// Process the record ourselves, but do not
 /// pass it on to the child Listener.
 /// </summary>
 /// <param name="record">The record.</param>
 public void ProcessRecordInternally(Record record)
 {
     if (record is BoundSheetRecord)
     {
         boundSheetRecords.Add(record);
     }
     else if (record is ExternSheetRecord)
     {
         externSheetRecords.Add(record);
     }
     else if (record is SSTRecord)
     {
         sstRecord = (SSTRecord)record;
     }
 }
Exemplo n.º 23
0
        /**
  * Handles UnknownRecords which appear within the row/cell records
  */
        private void AddUnknownRecord(Record rec)
        {
            // ony a few distinct record IDs are encountered by the existing POI test cases:
            // 0x1065 // many
            // 0x01C2 // several
            // 0x0034 // few
            // No documentation could be found for these

            // keep the unknown records for re-serialization
            _unknownRecords.Add(rec);
        }