Пример #1
0
        public override void VisitContainedRecords(RecordVisitor rv)
        {
            PositionTrackingVisitor stv = new PositionTrackingVisitor(rv, 0);
            //DBCells are serialized before row records.
            int blockCount = this.RowBlockCount;

            for (int blockIndex = 0; blockIndex < blockCount; blockIndex++)
            {
                // Serialize a block of rows.
                // Hold onto the position of the first row in the block
                int pos = 0;
                // Hold onto the size of this block that was serialized
                int rowBlockSize = VisitRowRecordsForBlock(blockIndex, rv);
                pos += rowBlockSize;
                // Serialize a block of cells for those rows
                int          startRowNumber = GetStartRowNumberForBlock(blockIndex);
                int          endRowNumber   = GetEndRowNumberForBlock(blockIndex);
                DBCellRecord cellRecord     = new DBCellRecord();
                // Note: Cell references start from the second row...
                int cellRefOffset = (rowBlockSize - RowRecord.ENCODED_SIZE);
                for (int row = startRowNumber; row <= endRowNumber; row++)
                {
                    if (_valuesAgg.RowHasCells(row))
                    {
                        stv.Position = 0;
                        _valuesAgg.VisitCellsForRow(row, stv);
                        int rowCellSize = stv.Position;
                        pos += rowCellSize;
                        // Add the offset to the first cell for the row into the
                        // DBCellRecord.
                        cellRecord.AddCellOffset((short)cellRefOffset);
                        cellRefOffset = rowCellSize;
                    }
                }
                // Calculate Offset from the start of a DBCellRecord to the first Row
                cellRecord.RowOffset = (pos);
                rv.VisitRecord(cellRecord);
            }
            foreach (Record _hyperlinkRecord in _hyperlinkRecordRecords)
            {
                rv.VisitRecord(_hyperlinkRecord);
            }
            foreach (Record _unknownRecord in _unknownRecords)
            {
                // Potentially breaking the file here since we don't know exactly where to write these records
                rv.VisitRecord(_unknownRecord);
            }
        }
Пример #2
0
        public override void VisitContainedRecords(RecordVisitor rv)
        {

            PositionTrackingVisitor stv = new PositionTrackingVisitor(rv, 0);
            //DBCells are serialized before row records.
            int blockCount = this.RowBlockCount;
            for (int blockIndex = 0; blockIndex < blockCount; blockIndex++)
            {
                // Serialize a block of rows.
                // Hold onto the position of the first row in the block
                int pos = 0;
                // Hold onto the size of this block that was serialized
                int rowBlockSize = VisitRowRecordsForBlock(blockIndex, rv);
                pos += rowBlockSize;
                // Serialize a block of cells for those rows
                int startRowNumber = GetStartRowNumberForBlock(blockIndex);
                int endRowNumber = GetEndRowNumberForBlock(blockIndex);
                DBCellRecord cellRecord = new DBCellRecord();
                // Note: Cell references start from the second row...
                int cellRefOffset = (rowBlockSize - RowRecord.ENCODED_SIZE);
                for (int row = startRowNumber; row <= endRowNumber; row++)
                {
                    if (_valuesAgg.RowHasCells(row))
                    {
                        stv.Position = 0;
                        _valuesAgg.VisitCellsForRow(row, stv);
                        int rowCellSize = stv.Position;
                        pos += rowCellSize;
                        // Add the offset to the first cell for the row into the
                        // DBCellRecord.
                        cellRecord.AddCellOffset((short)cellRefOffset);
                        cellRefOffset = rowCellSize;
                    }
                }
                // Calculate Offset from the start of a DBCellRecord to the first Row
                cellRecord.RowOffset = (pos);
                rv.VisitRecord(cellRecord);
            }
            for (int i = 0; i < _unknownRecords.Count; i++)
            {
                // Potentially breaking the file here since we don't know exactly where to write these records
                rv.VisitRecord((Record)_unknownRecords[i]);
            }
        }
Пример #3
0
        public void VisitContainedRecords(RecordVisitor rv, int offset)
        {

            PositionTrackingVisitor ptv = new PositionTrackingVisitor(rv, offset);

            bool haveSerializedIndex = false;

            int sheetOffset = offset;
            for (int k = 0; k < records.Count; k++)
            {
                RecordBase record = records[k];

                if (record is RecordAggregate)
                {
                    RecordAggregate agg = (RecordAggregate)record;
                    agg.VisitContainedRecords(ptv);
                    sheetOffset += agg.RecordSize;
                }
                else
                {
                    if (record is DefaultColWidthRecord)
                    {
                        ((DefaultColWidthRecord)record).offsetForFilePointer = sheetOffset;
                    }
                    ptv.VisitRecord((Record)record);
                    sheetOffset += record.RecordSize;
                }

                // If the BOF record was just serialized then add the IndexRecord
                if (record is BOFRecord)
                {
                    if (!haveSerializedIndex)
                    {
                        haveSerializedIndex = true;
                        // Add an optional UncalcedRecord. However, we should add
                        //  it in only the once, after the sheet's own BOFRecord.
                        // If there are diagrams, they have their own BOFRecords,
                        //  and one shouldn't go in after that!
                        if (_isUncalced)
                        {
                            UncalcedRecord rec = new UncalcedRecord();
                            ptv.VisitRecord(rec);
                            sheetOffset += rec.RecordSize;
                        }
                        //Can there be more than one BOF for a sheet? If not then we can
                        //remove this guard. So be safe it is left here.
                        if (_rowsAggregate != null)
                        {
                            // find forward distance to first RowRecord
                            int initRecsSize = GetSizeOfInitialSheetRecords(k);
                            int currentPos = ptv.Position;
                            IndexRecord indexRecord = _rowsAggregate.CreateIndexRecord(currentPos, initRecsSize, 0);
                            ptv.VisitRecord(indexRecord);
                            sheetOffset += indexRecord.RecordSize;
                        }
                    }
                }
            }
        }