Esempio n. 1
0
        private static IMargin CreateMarginRecord(MarginType margin, double size)
        {
            IMargin m;

            switch (margin)
            {
            case MarginType.LeftMargin:
                m = new LeftMarginRecord();
                break;

            case MarginType.RightMargin:
                m = new RightMarginRecord();
                break;

            case MarginType.TopMargin:
                m = new TopMarginRecord();
                break;

            case MarginType.BottomMargin:
                m = new BottomMarginRecord();
                break;

            default:
                throw new InvalidOperationException("Unknown margin constant:  " + margin);
            }
            m.Margin = size;
            return(m);
        }
Esempio n. 2
0
        /**
         * Sets the size of the margin in inches.
         * @param margin which margin to Get
         * @param size the size of the margin
         */
        public void SetMargin(MarginType margin, double size)
        {
            IMargin m = GetMarginRec(margin);

            if (m == null)
            {
                switch (margin)
                {
                case MarginType.LeftMargin:
                    _leftMargin = new LeftMarginRecord();
                    m           = _leftMargin;
                    break;

                case MarginType.RightMargin:
                    _rightMargin = new RightMarginRecord();
                    m            = _rightMargin;
                    break;

                case MarginType.TopMargin:
                    _topMargin = new TopMarginRecord();
                    m          = _topMargin;
                    break;

                case MarginType.BottomMargin:
                    _bottomMargin = new BottomMarginRecord();
                    m             = _bottomMargin;
                    break;

                default:
                    throw new InvalidOperationException("Unknown margin constant:  " + margin);
                }
            }
            m.Margin = size;
        }
 public override void Dispose()
 {
     _rowBreaksRecord    = null;
     _columnBreaksRecord = null;
     header        = null;
     footer        = null;
     _hCenter      = null;
     _vCenter      = null;
     _leftMargin   = null;
     _rightMargin  = null;
     _topMargin    = null;
     _bottomMargin = null;
     _pls          = null;
     printSetup    = null;
     _bitmap       = null;
 }
Esempio n. 4
0
        public InternalChart(RecordStream rs)
        {
            _plsRecords = new List <PLSAggregate>();
            records     = new List <RecordBase>(128);

            if (rs.PeekNextSid() != BOFRecord.sid)
            {
                throw new Exception("BOF record expected");
            }
            BOFRecord bof = (BOFRecord)rs.GetNext();

            if (bof.Type != BOFRecordType.Chart)
            {
                throw new RuntimeException("Bad BOF record type");
            }

            records.Add(bof);
            while (rs.HasNext())
            {
                int recSid = rs.PeekNextSid();

                Record.Record rec = rs.GetNext();
                if (recSid == EOFRecord.sid)
                {
                    records.Add(rec);
                    break;
                }

                if (recSid == ChartRecord.sid)
                {
                    continue;
                }

                if (recSid == ChartFRTInfoRecord.sid)
                {
                    _chartFrtInfo = (ChartFRTInfoRecord)rec;
                }
                else if (recSid == HeaderRecord.sid)
                {
                    header = (HeaderRecord)rec;
                }
                else if (recSid == FooterRecord.sid)
                {
                    footer = (FooterRecord)rec;
                }
                else if (recSid == HCenterRecord.sid)
                {
                    _hCenter = (HCenterRecord)rec;
                }
                else if (recSid == VCenterRecord.sid)
                {
                    _vCenter = (VCenterRecord)rec;
                }
                else if (recSid == LeftMarginRecord.sid)
                {
                    _leftMargin = (LeftMarginRecord)rec;
                }
                else if (recSid == RightMarginRecord.sid)
                {
                    _rightMargin = (RightMarginRecord)rec;
                }
                else if (recSid == TopMarginRecord.sid)
                {
                    _topMargin = (TopMarginRecord)rec;
                }
                else if (recSid == BottomMarginRecord.sid)
                {
                    _bottomMargin = (BottomMarginRecord)rec;
                }
                else if (recSid == UnknownRecord.PLS_004D) // PLS
                {
                    PLSAggregate        pls = new PLSAggregate(rs);
                    PLSAggregateVisitor rv  = new PLSAggregateVisitor(records);
                    pls.VisitContainedRecords(rv);
                    _plsRecords.Add(pls);

                    continue;
                }
                else if (recSid == PrintSetupRecord.sid)
                {
                    printSetup = (PrintSetupRecord)rec;
                }
                else if (recSid == PrintSizeRecord.sid)
                {
                    _printSize = (PrintSizeRecord)rec;
                }
                else if (recSid == HeaderFooterRecord.sid)
                {
                    HeaderFooterRecord hf = (HeaderFooterRecord)rec;
                    if (hf.IsCurrentSheet)
                    {
                        _headerFooter = hf;
                    }
                    else
                    {
                        _sviewHeaderFooters.Add(hf);
                    }
                }
                else if (recSid == ProtectRecord.sid)
                {
                    _protect = (ProtectRecord)rec;
                }
                records.Add(rec);
            }
        }
Esempio n. 5
0
        private bool ReadARecord(RecordStream rs)
        {
            switch (rs.PeekNextSid())
            {
            case HorizontalPageBreakRecord.sid:
                CheckNotPresent(_rowBreaksRecord);
                _rowBreaksRecord = (PageBreakRecord)rs.GetNext();
                break;

            case VerticalPageBreakRecord.sid:
                CheckNotPresent(_columnBreaksRecord);
                _columnBreaksRecord = (PageBreakRecord)rs.GetNext();
                break;

            case HeaderRecord.sid:
                CheckNotPresent(header);
                header = (HeaderRecord)rs.GetNext();
                break;

            case FooterRecord.sid:
                CheckNotPresent(footer);
                footer = (FooterRecord)rs.GetNext();
                break;

            case HCenterRecord.sid:
                CheckNotPresent(_hCenter);
                _hCenter = (HCenterRecord)rs.GetNext();
                break;

            case VCenterRecord.sid:
                CheckNotPresent(_vCenter);
                _vCenter = (VCenterRecord)rs.GetNext();
                break;

            case LeftMarginRecord.sid:
                CheckNotPresent(_leftMargin);
                _leftMargin = (LeftMarginRecord)rs.GetNext();
                break;

            case RightMarginRecord.sid:
                CheckNotPresent(_rightMargin);
                _rightMargin = (RightMarginRecord)rs.GetNext();
                break;

            case TopMarginRecord.sid:
                CheckNotPresent(_topMargin);
                _topMargin = (TopMarginRecord)rs.GetNext();
                break;

            case BottomMarginRecord.sid:
                CheckNotPresent(_bottomMargin);
                _bottomMargin = (BottomMarginRecord)rs.GetNext();
                break;

            case UnknownRecord.PLS_004D:     // PLS
                _plsRecords.Add(new PLSAggregate(rs));
                break;

            case PrintSetupRecord.sid:
                CheckNotPresent(printSetup);
                printSetup = (PrintSetupRecord)rs.GetNext();
                break;

            case UnknownRecord.BITMAP_00E9:     // BITMAP
                CheckNotPresent(_bitmap);
                _bitmap = rs.GetNext();
                break;

            case UnknownRecord.PRINTSIZE_0033:
                CheckNotPresent(_printSize);
                _printSize = rs.GetNext();
                break;

            case HeaderFooterRecord.sid:
                HeaderFooterRecord hf = (HeaderFooterRecord)rs.GetNext();
                if (hf.IsCurrentSheet)
                {
                    _headerFooter = hf;
                }
                else
                {
                    _sviewHeaderFooters.Add(hf);
                }
                break;

            default:
                // all other record types are not part of the PageSettingsBlock
                return(false);
            }
            return(true);
        }
        private bool ReadARecord(RecordStream rs)
        {
            switch (rs.PeekNextSid())
            {
            case HorizontalPageBreakRecord.sid:
                _rowBreaksRecord = (PageBreakRecord)rs.GetNext();
                _rowRecords.Add(_rowBreaksRecord);
                break;

            case VerticalPageBreakRecord.sid:
                _columnBreaksRecord = (PageBreakRecord)rs.GetNext();
                _rowRecords.Add(_columnBreaksRecord);
                break;

            case HeaderRecord.sid:
                header = (HeaderRecord)rs.GetNext();
                _rowRecords.Add(header);
                break;

            case FooterRecord.sid:
                footer = (FooterRecord)rs.GetNext();
                _rowRecords.Add(footer);
                break;

            case HCenterRecord.sid:
                _hCenter = (HCenterRecord)rs.GetNext();
                _rowRecords.Add(_hCenter);
                break;

            case VCenterRecord.sid:
                _vCenter = (VCenterRecord)rs.GetNext();
                _rowRecords.Add(_vCenter);
                break;

            case LeftMarginRecord.sid:
                _leftMargin = (LeftMarginRecord)rs.GetNext();
                _rowRecords.Add(_leftMargin);
                break;

            case RightMarginRecord.sid:
                _rightMargin = (RightMarginRecord)rs.GetNext();
                _rowRecords.Add(_rightMargin);
                break;

            case TopMarginRecord.sid:
                _topMargin = (TopMarginRecord)rs.GetNext();
                _rowRecords.Add(_topMargin);
                break;

            case BottomMarginRecord.sid:
                _bottomMargin = (BottomMarginRecord)rs.GetNext();
                _rowRecords.Add(_bottomMargin);
                break;

            case 0x004D:     // PLS
                _pls = rs.GetNext();
                _rowRecords.Add(_pls);
                break;

            case PrintSetupRecord.sid:
                printSetup = (PrintSetupRecord)rs.GetNext();
                _rowRecords.Add(printSetup);
                break;

            case 0x00E9:     // BITMAP
                _bitmap = rs.GetNext();
                _rowRecords.Add(_bitmap);
                break;

            default:
                // all other record types are not part of the PageSettingsBlock
                return(false);
            }
            return(true);
        }
        /**
         * Writes out this sheet.  First writes out the standard sheet
         * information then writes out each row in turn.
         * Once all the rows have been written out, it retrospectively adjusts
         * the offset references in the file
         *
         * @exception IOException
         */
        public void write()
        {
            Assert.verify(rows != null);

            // This worksheet consists of just one chart, so write it and return
            if (chartOnly)
                {
                drawingWriter.write(outputFile);
                return;
                }

            BOFRecord bof = new BOFRecord(BOFRecord.sheet);
            outputFile.write(bof);

            // Compute the number of blocks of 32 rows that will be needed
            int numBlocks = numRows / 32;
            if (numRows - numBlocks * 32 != 0)
                numBlocks++;

            int indexPos = outputFile.getPos();

            // Write the index record out now in order to serve as a place holder
            // The bof passed in is the bof of the workbook, not this sheet
            IndexRecord indexRecord = new IndexRecord(0, numRows, numBlocks);
            outputFile.write(indexRecord);

            if (settings.getAutomaticFormulaCalculation())
                {
                CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.automatic);
                outputFile.write(cmr);
                }
            else
                {
                CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.manual);
                outputFile.write(cmr);
                }

            CalcCountRecord ccr = new CalcCountRecord(0x64);
            outputFile.write(ccr);

            RefModeRecord rmr = new RefModeRecord();
            outputFile.write(rmr);

            IterationRecord itr = new IterationRecord(false);
            outputFile.write(itr);

            DeltaRecord dtr = new DeltaRecord(0.001);
            outputFile.write(dtr);

            SaveRecalcRecord srr = new SaveRecalcRecord(settings.getRecalculateFormulasBeforeSave());
            outputFile.write(srr);

            PrintHeadersRecord phr = new PrintHeadersRecord(settings.getPrintHeaders());
            outputFile.write(phr);

            PrintGridLinesRecord pglr = new PrintGridLinesRecord(settings.getPrintGridLines());
            outputFile.write(pglr);

            GridSetRecord gsr = new GridSetRecord(true);
            outputFile.write(gsr);

            GuttersRecord gutr = new GuttersRecord();
            gutr.setMaxColumnOutline(maxColumnOutlineLevel + 1);
            gutr.setMaxRowOutline(maxRowOutlineLevel + 1);

            outputFile.write(gutr);

            DefaultRowHeightRecord drhr = new DefaultRowHeightRecord
             (settings.getDefaultRowHeight(),
              settings.getDefaultRowHeight() !=
                        SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT);
            outputFile.write(drhr);

            if (maxRowOutlineLevel > 0)
                workspaceOptions.setRowOutlines(true);

            if (maxColumnOutlineLevel > 0)
                workspaceOptions.setColumnOutlines(true);

            workspaceOptions.setFitToPages(settings.getFitToPages());
            outputFile.write(workspaceOptions);

            if (rowBreaks.Count > 0)
                {
                int[] rb = new int[rowBreaks.Count];
                for (int i = 0; i < rb.Length; i++)
                    rb[i] = (int)rowBreaks[i];

                HorizontalPageBreaksRecord hpbr = new HorizontalPageBreaksRecord(rb);
                outputFile.write(hpbr);
                }

            if (columnBreaks.Count > 0)
                {
                int[] rb = new int[columnBreaks.Count];

                for (int i = 0; i < rb.Length; i++)
                    rb[i] = (int)columnBreaks[i];

                VerticalPageBreaksRecord hpbr = new VerticalPageBreaksRecord(rb);
                outputFile.write(hpbr);
                }

            HeaderRecord header = new HeaderRecord(settings.getHeader().ToString());
            outputFile.write(header);

            FooterRecord footer = new FooterRecord(settings.getFooter().ToString());
            outputFile.write(footer);

            HorizontalCentreRecord hcr = new HorizontalCentreRecord(settings.isHorizontalCentre());
            outputFile.write(hcr);

            VerticalCentreRecord vcr = new VerticalCentreRecord(settings.isVerticalCentre());
            outputFile.write(vcr);

            // Write out the margins if they don't equal the default
            if (settings.getLeftMargin() != settings.getDefaultWidthMargin())
                {
                MarginRecord mr = new LeftMarginRecord(settings.getLeftMargin());
                outputFile.write(mr);
                }

            if (settings.getRightMargin() != settings.getDefaultWidthMargin())
                {
                MarginRecord mr = new RightMarginRecord(settings.getRightMargin());
                outputFile.write(mr);
                }

            if (settings.getTopMargin() != settings.getDefaultHeightMargin())
                {
                MarginRecord mr = new TopMarginRecord(settings.getTopMargin());
                outputFile.write(mr);
                }

            if (settings.getBottomMargin() != settings.getDefaultHeightMargin())
                {
                MarginRecord mr = new BottomMarginRecord(settings.getBottomMargin());
                outputFile.write(mr);
                }

            if (plsRecord != null)
                outputFile.write(plsRecord);

            SetupRecord setup = new SetupRecord(settings);
            outputFile.write(setup);

            if (settings.isProtected())
                {
                ProtectRecord pr = new ProtectRecord(settings.isProtected());
                outputFile.write(pr);

                ScenarioProtectRecord spr = new ScenarioProtectRecord(settings.isProtected());
                outputFile.write(spr);

                ObjectProtectRecord opr = new ObjectProtectRecord(settings.isProtected());
                outputFile.write(opr);

                if (settings.getPassword() != null)
                    {
                    PasswordRecord pw = new PasswordRecord(settings.getPassword());
                    outputFile.write(pw);
                    }
                else if (settings.getPasswordHash() != 0)
                    {
                    PasswordRecord pw = new PasswordRecord(settings.getPasswordHash());
                    outputFile.write(pw);
                    }
                }

            indexRecord.setDataStartPosition(outputFile.getPos());
            DefaultColumnWidth dcw = new DefaultColumnWidth(settings.getDefaultColumnWidth());
            outputFile.write(dcw);

            // Get a handle to the normal styles
            WritableCellFormat normalStyle = sheet.getWorkbook().getStyles().getNormalStyle();
            WritableCellFormat defaultDateFormat = sheet.getWorkbook().getStyles().getDefaultDateFormat();

            // Write out all the column formats
            foreach (ColumnInfoRecord cir in columnFormats)
                {
                // Writing out the column info with index 0x100 causes excel to crash
                if (cir.getColumn() < 0x100)
                    outputFile.write(cir);

                XFRecord xfr = cir.getCellFormat();

                if (xfr != normalStyle && cir.getColumn() < 0x100)
                    {
                    // Make this the format for every cell in the column
                    Cell[] cells = getColumn(cir.getColumn());

                    for (int i = 0; i < cells.Length; i++)
                        {
                        if (cells[i] != null &&
                            (cells[i].getCellFormat() == normalStyle ||
                             cells[i].getCellFormat() == defaultDateFormat))
                            {
                            // The cell has no overriding format specified, so
                            // set it to the column default
                            ((WritableCell)cells[i]).setCellFormat(xfr);
                            }
                        }
                    }
                }

            // Write out the auto filter
            if (autoFilter != null)
                autoFilter.write(outputFile);

            DimensionRecord dr = new DimensionRecord(numRows, numCols);
            outputFile.write(dr);

            // Write out all the rows, in blocks of 32
            for (int block = 0; block < numBlocks; block++)
                {
                DBCellRecord dbcell = new DBCellRecord(outputFile.getPos());

                int blockRows = System.Math.Min(32, numRows - block * 32);
                bool firstRow = true;

                // First write out all the row records
                for (int i = block * 32; i < block * 32 + blockRows; i++)
                    {
                    if (rows[i] != null)
                        {
                        rows[i].write(outputFile);
                        if (firstRow)
                            {
                            dbcell.setCellOffset(outputFile.getPos());
                            firstRow = false;
                            }
                        }
                    }

                // Now write out all the cells
                for (int i = block * 32; i < block * 32 + blockRows; i++)
                    {
                    if (rows[i] != null)
                        {
                        dbcell.addCellRowPosition(outputFile.getPos());
                        rows[i].writeCells(outputFile);
                        }
                    }

                // Now set the current file position in the index record
                indexRecord.addBlockPosition(outputFile.getPos());

                // Set the position of the file pointer and write out the DBCell
                // record
                dbcell.setPosition(outputFile.getPos());
                outputFile.write(dbcell);
                }

            // Do the drawings and charts if enabled
            if (!workbookSettings.getDrawingsDisabled())
                drawingWriter.write(outputFile);

            Window2Record w2r = new Window2Record(settings);
            outputFile.write(w2r);

            // Handle the frozen panes
            if (settings.getHorizontalFreeze() != 0 || settings.getVerticalFreeze() != 0)
                {
                PaneRecord pr = new PaneRecord(settings.getHorizontalFreeze(),settings.getVerticalFreeze());
                outputFile.write(pr);

                // Handle the selection record.  First, there will always be a top left
                SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0);
                outputFile.write(sr);

                // Top right
                if (settings.getHorizontalFreeze() != 0)
                    {
                    sr = new SelectionRecord(SelectionRecord.upperRight, settings.getHorizontalFreeze(), 0);
                    outputFile.write(sr);
                    }

                // Bottom left
                if (settings.getVerticalFreeze() != 0)
                    {
                    sr = new SelectionRecord(SelectionRecord.lowerLeft, 0, settings.getVerticalFreeze());
                    outputFile.write(sr);
                    }

                // Bottom right
                if (settings.getHorizontalFreeze() != 0 &&
                    settings.getVerticalFreeze() != 0)
                    {
                    sr = new SelectionRecord(SelectionRecord.lowerRight,settings.getHorizontalFreeze(),settings.getVerticalFreeze());
                    outputFile.write(sr);
                    }

                Weird1Record w1r = new Weird1Record();
                outputFile.write(w1r);
                }
            else
                {
                // No frozen panes - just write out the selection record for the
                // whole sheet
                SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0);
                outputFile.write(sr);
                }

            // Handle the zoom factor
            if (settings.getZoomFactor() != 100)
                {
                SCLRecord sclr = new SCLRecord(settings.getZoomFactor());
                outputFile.write(sclr);
                }

            // Now write out all the merged cells
            mergedCells.write(outputFile);

            // Write out all the hyperlinks
            foreach (WritableHyperlink hlr in hyperlinks)
                outputFile.write(hlr);

            if (buttonPropertySet != null)
                outputFile.write(buttonPropertySet);

            // Write out the data validations
            if (dataValidation != null || validatedCells.Count > 0)
                writeDataValidation();

            // Write out the conditional formats
            if (conditionalFormats != null && conditionalFormats.Count > 0)
                {
                foreach (ConditionalFormat cf in conditionalFormats)
                    cf.write(outputFile);
                }

            EOFRecord eof = new EOFRecord();
            outputFile.write(eof);

            // Now the various cross reference offsets have been calculated,
            // retrospectively set the values in the output file
            outputFile.setData(indexRecord.getData(), indexPos + 4);
        }
        /**
         * Reads in the contents of this sheet
         */
        public void read()
        {
            Record r = null;
            BaseSharedFormulaRecord sharedFormula = null;
            bool sharedFormulaAdded = false;

            bool cont = true;

            // Set the position within the file
            excelFile.setPos(startPosition);

            // Handles to the last drawing and obj records
            MsoDrawingRecord msoRecord = null;
            ObjRecord objRecord = null;
            bool firstMsoRecord = true;

            // Handle to the last conditional format record
            ConditionalFormat condFormat = null;

            // Handle to the autofilter records
            FilterModeRecord filterMode = null;
            AutoFilterInfoRecord autoFilterInfo = null;

            // A handle to window2 record
            Window2Record window2Record = null;

            // A handle to printgridlines record
            PrintGridLinesRecord printGridLinesRecord = null;

            // A handle to printheaders record
            PrintHeadersRecord printHeadersRecord = null;

            // Hash map of comments, indexed on objectId.  As each corresponding
            // note record is encountered, these are removed from the array
            Dictionary<uint,Comment> comments = new Dictionary<uint,Comment>();

            // A list of object ids - used for cross referencing
            ArrayList objectIds = new ArrayList();

            // A handle to a continue record read in
            ContinueRecord continueRecord = null;

            while (cont)
                {
                r = excelFile.next();
                Type type = r.getType();

                if (type == Type.UNKNOWN && r.getCode() == 0)
                    {
                    //logger.warn("Biff code zero found");

                    // Try a dimension record
                    if (r.getLength() == 0xa)
                        {
                        //logger.warn("Biff code zero found - trying a dimension record.");
                        r.setType(Type.DIMENSION);
                        }
                    else
                        {
                        //logger.warn("Biff code zero found - Ignoring.");
                        }
                    }

                if (type == Type.DIMENSION)
                    {
                    DimensionRecord dr = null;

                    if (workbookBof.isBiff8())
                        {
                        dr = new DimensionRecord(r);
                        }
                    else
                        {
                        dr = new DimensionRecord(r, DimensionRecord.biff7);
                        }
                    numRows = dr.getNumberOfRows();
                    numCols = dr.getNumberOfColumns();
                    cells = new Cell[numRows, numCols];
                    }
                else if (type == Type.LABELSST)
                    {
                    LabelSSTRecord label = new LabelSSTRecord(r,
                                                              sharedStrings,
                                                              formattingRecords,
                                                              sheet);
                    addCell(label);
                    }
                else if (type == Type.RK || type == Type.RK2)
                    {
                    RKRecord rkr = new RKRecord(r, formattingRecords, sheet);

                    if (formattingRecords.isDate(rkr.getXFIndex()))
                        {
                        DateCell dc = new DateRecord
                          (rkr, rkr.getXFIndex(), formattingRecords, nineteenFour, sheet);
                        addCell(dc);
                        }
                    else
                        {
                        addCell(rkr);
                        }
                    }
                else if (type == Type.HLINK)
                    {
                    HyperlinkRecord hr = new HyperlinkRecord(r, sheet, workbookSettings);
                    hyperlinks.Add(hr);
                    }
                else if (type == Type.MERGEDCELLS)
                    {
                    MergedCellsRecord mc = new MergedCellsRecord(r, sheet);
                    if (mergedCells == null)
                        {
                        mergedCells = mc.getRanges();
                        }
                    else
                        {
                        Range[] newMergedCells =
                          new Range[mergedCells.Length + mc.getRanges().Length];
                        System.Array.Copy(mergedCells, 0, newMergedCells, 0,
                                         mergedCells.Length);
                        System.Array.Copy(mc.getRanges(),
                                         0,
                                         newMergedCells, mergedCells.Length,
                                         mc.getRanges().Length);
                        mergedCells = newMergedCells;
                        }
                    }
                else if (type == Type.MULRK)
                    {
                    MulRKRecord mulrk = new MulRKRecord(r);

                    // Get the individual cell records from the multiple record
                    int num = mulrk.getNumberOfColumns();
                    int ixf = 0;
                    for (int i = 0; i < num; i++)
                        {
                        ixf = mulrk.getXFIndex(i);

                        NumberValue nv = new NumberValue
                          (mulrk.getRow(),
                           mulrk.getFirstColumn() + i,
                           RKHelper.getDouble(mulrk.getRKNumber(i)),
                           ixf,
                           formattingRecords,
                           sheet);

                        if (formattingRecords.isDate(ixf))
                            {
                            DateCell dc = new DateRecord(nv,
                                                         ixf,
                                                         formattingRecords,
                                                         nineteenFour,
                                                         sheet);
                            addCell(dc);
                            }
                        else
                            {
                            nv.setNumberFormat(formattingRecords.getNumberFormat(ixf));
                            addCell(nv);
                            }
                        }
                    }
                else if (type == Type.NUMBER)
                    {
                    NumberRecord nr = new NumberRecord(r, formattingRecords, sheet);

                    if (formattingRecords.isDate(nr.getXFIndex()))
                        {
                        DateCell dc = new DateRecord(nr,nr.getXFIndex(),formattingRecords,nineteenFour, sheet);
                        addCell(dc);
                        }
                    else
                        addCell(nr);
                    }
                else if (type == Type.BOOLERR)
                    {
                    BooleanRecord br = new BooleanRecord(r, formattingRecords, sheet);

                    if (br.isError())
                        {
                        ErrorRecord er = new ErrorRecord(br.getRecord(), formattingRecords,
                                                         sheet);
                        addCell(er);
                        }
                    else
                        {
                        addCell(br);
                        }
                    }
                else if (type == Type.PRINTGRIDLINES)
                    {
                    printGridLinesRecord = new PrintGridLinesRecord(r);
                    settings.setPrintGridLines(printGridLinesRecord.getPrintGridLines());
                    }
                else if (type == Type.PRINTHEADERS)
                    {
                    printHeadersRecord = new PrintHeadersRecord(r);
                    settings.setPrintHeaders(printHeadersRecord.getPrintHeaders());
                    }
                else if (type == Type.WINDOW2)
                    {
                    window2Record = null;

                    if (workbookBof.isBiff8())
                        {
                        window2Record = new Window2Record(r);
                        }
                    else
                        {
                        window2Record = new Window2Record(r, Window2Record.biff7);
                        }

                    settings.setShowGridLines(window2Record.getShowGridLines());
                    settings.setDisplayZeroValues(window2Record.getDisplayZeroValues());
                    settings.setSelected(true);
                    settings.setPageBreakPreviewMode(window2Record.isPageBreakPreview());
                    }
                else if (type == Type.PANE)
                    {
                    PaneRecord pr = new PaneRecord(r);

                    if (window2Record != null &&
                        window2Record.getFrozen())
                        {
                        settings.setVerticalFreeze(pr.getRowsVisible());
                        settings.setHorizontalFreeze(pr.getColumnsVisible());
                        }
                    }
                else if (type == Type.CONTINUE)
                    {
                    // don't know what this is for, but keep hold of it anyway
                    continueRecord = new ContinueRecord(r);
                    }
                else if (type == Type.NOTE)
                    {
                    if (!workbookSettings.getDrawingsDisabled())
                        {
                        NoteRecord nr = new NoteRecord(r);

                        // Get the comment for the object id
                        if (!comments.ContainsKey(nr.getObjectId()))
                            {
                            //logger.warn(" cannot find comment for note id " + nr.getObjectId() + "...ignoring");
                            }
                        else
                            {
                            Comment comment = comments[nr.getObjectId()];
                            comments.Remove(nr.getObjectId());

                            comment.setNote(nr);
                            drawings.Add(comment);
                            addCellComment(comment.getColumn(),
                                           comment.getRow(),
                                           comment.getText(),
                                           comment.getWidth(),
                                           comment.getHeight());
                            }
                        }
                    }
                else if (type == Type.ARRAY)
                    {
                    ;
                    }
                else if (type == Type.PROTECT)
                    {
                    ProtectRecord pr = new ProtectRecord(r);
                    settings.setProtected(pr.isProtected());
                    }
                else if (type == Type.SHAREDFORMULA)
                    {
                    if (sharedFormula == null)
                        {
                        //logger.warn("Shared template formula is null - " +
                        //            "trying most recent formula template");
                        SharedFormulaRecord lastSharedFormula = (SharedFormulaRecord)sharedFormulas[sharedFormulas.Count - 1];

                        if (lastSharedFormula != null)
                            sharedFormula = lastSharedFormula.getTemplateFormula();
                        }

                    SharedFormulaRecord sfr = new SharedFormulaRecord(r, sharedFormula, workbook, workbook, sheet);
                    sharedFormulas.Add(sfr);
                    sharedFormula = null;
                    }
                else if (type == Type.FORMULA || type == Type.FORMULA2)
                    {
                    FormulaRecord fr = new FormulaRecord(r,
                                                         excelFile,
                                                         formattingRecords,
                                                         workbook,
                                                         workbook,
                                                         sheet,
                                                         workbookSettings);

                    if (fr.isShared())
                        {
                        BaseSharedFormulaRecord prevSharedFormula = sharedFormula;
                        sharedFormula = (BaseSharedFormulaRecord)fr.getFormula();

                        // See if it fits in any of the shared formulas
                        sharedFormulaAdded = addToSharedFormulas(sharedFormula);

                        if (sharedFormulaAdded)
                            {
                            sharedFormula = prevSharedFormula;
                            }

                        // If we still haven't added the previous base shared formula,
                        // revert it to an ordinary formula and add it to the cell
                        if (!sharedFormulaAdded && prevSharedFormula != null)
                            {
                            // Do nothing.  It's possible for the biff file to contain the
                            // record sequence
                            // FORMULA-SHRFMLA-FORMULA-SHRFMLA-FORMULA-FORMULA-FORMULA
                            // ie. it first lists all the formula templates, then it
                            // lists all the individual formulas
                            addCell(revertSharedFormula(prevSharedFormula));
                            }
                        }
                    else
                        {
                        Cell cell = fr.getFormula();
                        try
                            {
                            // See if the formula evaluates to date
                            if (fr.getFormula().getType() == CellType.NUMBER_FORMULA)
                                {
                                NumberFormulaRecord nfr = (NumberFormulaRecord)fr.getFormula();
                                if (formattingRecords.isDate(nfr.getXFIndex()))
                                    {
                                    cell = new DateFormulaRecord(nfr,
                                                                 formattingRecords,
                                                                 workbook,
                                                                 workbook,
                                                                 nineteenFour,
                                                                 sheet);
                                    }
                                }

                            addCell(cell);
                            }
                        catch (FormulaException e)
                            {
                            // Something has gone wrong trying to read the formula data eg. it
                            // might be unsupported biff7 data
                            //logger.warn(CellReferenceHelper.getCellReference(cell.getColumn(), cell.getRow()) + " " + e.Message);
                            }
                        }
                    }
                else if (type == Type.LABEL)
                    {
                    LabelRecord lr = null;

                    if (workbookBof.isBiff8())
                        {
                        lr = new LabelRecord(r, formattingRecords, sheet, workbookSettings);
                        }
                    else
                        {
                        lr = new LabelRecord(r, formattingRecords, sheet, workbookSettings,
                                             LabelRecord.biff7);
                        }
                    addCell(lr);
                    }
                else if (type == Type.RSTRING)
                    {
                    RStringRecord lr = null;

                    // RString records are obsolete in biff 8
                    Assert.verify(!workbookBof.isBiff8());
                    lr = new RStringRecord(r, formattingRecords,
                                           sheet, workbookSettings,
                                           RStringRecord.biff7);
                    addCell(lr);
                    }
                else if (type == Type.NAME)
                    {
                    ;
                    }
                else if (type == Type.PASSWORD)
                    {
                    PasswordRecord pr = new PasswordRecord(r);
                    settings.setPasswordHash(pr.getPasswordHash());
                    }
                else if (type == Type.ROW)
                    {
                    RowRecord rr = new RowRecord(r);

                    // See if the row has anything funny about it
                    if (!rr.isDefaultHeight() ||
                        !rr.matchesDefaultFontHeight() ||
                        rr.isCollapsed() ||
                        rr.hasDefaultFormat() ||
                        rr.getOutlineLevel() != 0)
                        {
                        rowProperties.Add(rr);
                        }
                    }
                else if (type == Type.BLANK)
                    {
                    if (!workbookSettings.getIgnoreBlanks())
                        {
                        BlankCell bc = new BlankCell(r, formattingRecords, sheet);
                        addCell(bc);
                        }
                    }
                else if (type == Type.MULBLANK)
                    {
                    if (!workbookSettings.getIgnoreBlanks())
                        {
                        MulBlankRecord mulblank = new MulBlankRecord(r);

                        // Get the individual cell records from the multiple record
                        int num = mulblank.getNumberOfColumns();

                        for (int i = 0; i < num; i++)
                            {
                            int ixf = mulblank.getXFIndex(i);

                            MulBlankCell mbc = new MulBlankCell
                              (mulblank.getRow(),
                               mulblank.getFirstColumn() + i,
                               ixf,
                               formattingRecords,
                               sheet);

                            addCell(mbc);
                            }
                        }
                    }
                else if (type == Type.SCL)
                    {
                    SCLRecord scl = new SCLRecord(r);
                    settings.setZoomFactor(scl.getZoomFactor());
                    }
                else if (type == Type.COLINFO)
                    {
                    ColumnInfoRecord cir = new ColumnInfoRecord(r);
                    columnInfosArray.Add(cir);
                    }
                else if (type == Type.HEADER)
                    {
                    HeaderRecord hr = null;
                    if (workbookBof.isBiff8())
                        hr = new HeaderRecord(r, workbookSettings);
                    else
                        hr = new HeaderRecord(r, workbookSettings, HeaderRecord.biff7);

                    HeaderFooter header = new HeaderFooter(hr.getHeader());
                    settings.setHeader(header);
                    }
                else if (type == Type.FOOTER)
                    {
                    FooterRecord fr = null;
                    if (workbookBof.isBiff8())
                        {
                        fr = new FooterRecord(r, workbookSettings);
                        }
                    else
                        {
                        fr = new FooterRecord(r, workbookSettings, FooterRecord.biff7);
                        }

                    HeaderFooter footer = new HeaderFooter(fr.getFooter());
                    settings.setFooter(footer);
                    }
                else if (type == Type.SETUP)
                    {
                    SetupRecord sr = new SetupRecord(r);

                    // If the setup record has its not initialized bit set, then
                    // use the sheet settings default values
                    if (sr.getInitialized())
                        {
                        if (sr.isPortrait())
                            {
                            settings.setOrientation(PageOrientation.PORTRAIT);
                            }
                        else
                            {
                            settings.setOrientation(PageOrientation.LANDSCAPE);
                            }
                        if (sr.isRightDown())
                            {
                            settings.setPageOrder(PageOrder.RIGHT_THEN_DOWN);
                            }
                        else
                            {
                            settings.setPageOrder(PageOrder.DOWN_THEN_RIGHT);
                            }
                        settings.setPaperSize(PaperSize.getPaperSize(sr.getPaperSize()));
                        settings.setHeaderMargin(sr.getHeaderMargin());
                        settings.setFooterMargin(sr.getFooterMargin());
                        settings.setScaleFactor(sr.getScaleFactor());
                        settings.setPageStart(sr.getPageStart());
                        settings.setFitWidth(sr.getFitWidth());
                        settings.setFitHeight(sr.getFitHeight());
                        settings.setHorizontalPrintResolution
                          (sr.getHorizontalPrintResolution());
                        settings.setVerticalPrintResolution(sr.getVerticalPrintResolution());
                        settings.setCopies(sr.getCopies());

                        if (workspaceOptions != null)
                            {
                            settings.setFitToPages(workspaceOptions.getFitToPages());
                            }
                        }
                    }
                else if (type == Type.WSBOOL)
                    {
                    workspaceOptions = new WorkspaceInformationRecord(r);
                    }
                else if (type == Type.DEFCOLWIDTH)
                    {
                    DefaultColumnWidthRecord dcwr = new DefaultColumnWidthRecord(r);
                    settings.setDefaultColumnWidth(dcwr.getWidth());
                    }
                else if (type == Type.DEFAULTROWHEIGHT)
                    {
                    DefaultRowHeightRecord drhr = new DefaultRowHeightRecord(r);
                    if (drhr.getHeight() != 0)
                        {
                        settings.setDefaultRowHeight(drhr.getHeight());
                        }
                    }
                else if (type == Type.CONDFMT)
                    {
                    ConditionalFormatRangeRecord cfrr =
                      new ConditionalFormatRangeRecord(r);
                    condFormat = new ConditionalFormat(cfrr);
                    conditionalFormats.Add(condFormat);
                    }
                else if (type == Type.CF)
                    {
                    ConditionalFormatRecord cfr = new ConditionalFormatRecord(r);
                    condFormat.addCondition(cfr);
                    }
                else if (type == Type.FILTERMODE)
                    {
                    filterMode = new FilterModeRecord(r);
                    }
                else if (type == Type.AUTOFILTERINFO)
                    {
                    autoFilterInfo = new AutoFilterInfoRecord(r);
                    }
                else if (type == Type.AUTOFILTER)
                    {
                    if (!workbookSettings.getAutoFilterDisabled())
                        {
                        AutoFilterRecord af = new AutoFilterRecord(r);

                        if (autoFilter == null)
                            {
                            autoFilter = new AutoFilter(filterMode, autoFilterInfo);
                            filterMode = null;
                            autoFilterInfo = null;
                            }

                        autoFilter.add(af);
                        }
                    }
                else if (type == Type.LEFTMARGIN)
                    {
                    MarginRecord m = new LeftMarginRecord(r);
                    settings.setLeftMargin(m.getMargin());
                    }
                else if (type == Type.RIGHTMARGIN)
                    {
                    MarginRecord m = new RightMarginRecord(r);
                    settings.setRightMargin(m.getMargin());
                    }
                else if (type == Type.TOPMARGIN)
                    {
                    MarginRecord m = new TopMarginRecord(r);
                    settings.setTopMargin(m.getMargin());
                    }
                else if (type == Type.BOTTOMMARGIN)
                    {
                    MarginRecord m = new BottomMarginRecord(r);
                    settings.setBottomMargin(m.getMargin());
                    }
                else if (type == Type.HORIZONTALPAGEBREAKS)
                    {
                    HorizontalPageBreaksRecord dr = null;

                    if (workbookBof.isBiff8())
                        {
                        dr = new HorizontalPageBreaksRecord(r);
                        }
                    else
                        {
                        dr = new HorizontalPageBreaksRecord
                          (r, HorizontalPageBreaksRecord.biff7);
                        }
                    rowBreaks = dr.getRowBreaks();
                    }
                else if (type == Type.VERTICALPAGEBREAKS)
                    {
                    VerticalPageBreaksRecord dr = null;

                    if (workbookBof.isBiff8())
                        {
                        dr = new VerticalPageBreaksRecord(r);
                        }
                    else
                        {
                        dr = new VerticalPageBreaksRecord
                          (r, VerticalPageBreaksRecord.biff7);
                        }
                    columnBreaks = dr.getColumnBreaks();
                    }
                else if (type == Type.PLS)
                    {
                    plsRecord = new PLSRecord(r);

                    // Check for Continue records
                    while (excelFile.peek().getType() == Type.CONTINUE)
                        {
                        r.addContinueRecord(excelFile.next());
                        }
                    }
                else if (type == Type.DVAL)
                    {
                    if (!workbookSettings.getCellValidationDisabled())
                        {
                        DataValidityListRecord dvlr = new DataValidityListRecord(r);
                        if (dvlr.getObjectId() == DataValidation.DEFAULT_OBJECT_ID)
                            {
                            if (msoRecord != null && objRecord == null)
                                {
                                // there is a drop down associated with this data validation
                                if (drawingData == null)
                                    drawingData = new DrawingData();

                                Drawing2 d2 = new Drawing2(msoRecord, drawingData,
                                                           workbook.getDrawingGroup());
                                drawings.Add(d2);
                                msoRecord = null;

                                dataValidation = new DataValidation(dvlr);
                                }
                            else
                                {
                                // no drop down
                                dataValidation = new DataValidation(dvlr);
                                }
                            }
                        else if (objectIds.Contains(dvlr.getObjectId()))
                            dataValidation = new DataValidation(dvlr);
                        else
                            {
                            //logger.warn("object id " + dvlr.getObjectId() + " referenced " +
                            //            " by data validity list record not found - ignoring");
                            }
                        }
                    }
                else if (type == Type.HCENTER)
                    {
                    CentreRecord hr = new CentreRecord(r);
                    settings.setHorizontalCentre(hr.isCentre());
                    }
                else if (type == Type.VCENTER)
                    {
                    CentreRecord vc = new CentreRecord(r);
                    settings.setVerticalCentre(vc.isCentre());
                    }
                else if (type == Type.DV)
                    {
                    if (!workbookSettings.getCellValidationDisabled())
                        {
                        DataValiditySettingsRecord dvsr =
                          new DataValiditySettingsRecord(r,
                                                         workbook,
                                                         workbook,
                                                         workbook.getSettings());
                        if (dataValidation != null)
                            {
                            dataValidation.add(dvsr);
                            addCellValidation(dvsr.getFirstColumn(),
                                              dvsr.getFirstRow(),
                                              dvsr.getLastColumn(),
                                              dvsr.getLastRow(),
                                              dvsr);
                            }
                        else
                            {
                            //logger.warn("cannot add data validity settings");
                            }
                        }
                    }
                else if (type == Type.OBJ)
                    {
                    objRecord = new ObjRecord(r);

                    if (!workbookSettings.getDrawingsDisabled())
                        {
                        // sometimes excel writes out continue records instead of drawing
                        // records, so forcibly hack the stashed continue record into
                        // a drawing record
                        if (msoRecord == null && continueRecord != null)
                            {
                            //logger.warn("Cannot find drawing record - using continue record");
                            msoRecord = new MsoDrawingRecord(continueRecord.getRecord());
                            continueRecord = null;
                            }
                        handleobjectRecord(objRecord, msoRecord, comments);
                        objectIds.Add((objRecord.getObjectId()));
                        }

                    // Save chart handling until the chart BOF record appears
                    if (objRecord.getType() != ObjRecord.CHART)
                        {
                        objRecord = null;
                        msoRecord = null;
                        }
                    }
                else if (type == Type.MSODRAWING)
                    {
                    if (!workbookSettings.getDrawingsDisabled())
                        {
                        if (msoRecord != null)
                            {
                            // For form controls, a rogue MSODRAWING record can crop up
                            // after the main one.  Add these into the drawing data
                            drawingData.addRawData(msoRecord.getData());
                            }
                        msoRecord = new MsoDrawingRecord(r);

                        if (firstMsoRecord)
                            {
                            msoRecord.setFirst();
                            firstMsoRecord = false;
                            }
                        }
                    }
                else if (type == Type.BUTTONPROPERTYSET)
                    {
                    buttonPropertySet = new ButtonPropertySetRecord(r);
                    }
                else if (type == Type.CALCMODE)
                    {
                    CalcModeRecord cmr = new CalcModeRecord(r);
                    settings.setAutomaticFormulaCalculation(cmr.isAutomatic());
                    }
                else if (type == Type.SAVERECALC)
                    {
                    SaveRecalcRecord cmr = new SaveRecalcRecord(r);
                    settings.setRecalculateFormulasBeforeSave(cmr.getRecalculateOnSave());
                    }
                else if (type == Type.GUTS)
                    {
                    GuttersRecord gr = new GuttersRecord(r);
                    maxRowOutlineLevel =
                      gr.getRowOutlineLevel() > 0 ? gr.getRowOutlineLevel() - 1 : 0;
                    maxColumnOutlineLevel =
                      gr.getColumnOutlineLevel() > 0 ? gr.getRowOutlineLevel() - 1 : 0;
                    }
                else if (type == Type.BOF)
                    {
                    BOFRecord br = new BOFRecord(r);
                    Assert.verify(!br.isWorksheet());

                    int startpos = excelFile.getPos() - r.getLength() - 4;

                    // Skip to the end of the nested bof
                    // Thanks to Rohit for spotting this
                    Record r2 = excelFile.next();
                    while (r2.getCode() != Type.EOF.value)
                        r2 = excelFile.next();

                    if (br.isChart())
                        {
                        if (!workbook.getWorkbookBof().isBiff8())
                            {
                            //logger.warn("only biff8 charts are supported");
                            }
                        else
                            {
                            if (drawingData == null)
                                drawingData = new DrawingData();

                            if (!workbookSettings.getDrawingsDisabled())
                                {
                                Chart chart = new Chart(msoRecord, objRecord, drawingData,
                                                        startpos, excelFile.getPos(),
                                                        excelFile, workbookSettings);
                                charts.Add(chart);

                                if (workbook.getDrawingGroup() != null)
                                    workbook.getDrawingGroup().add(chart);
                                }
                            }

                        // Reset the drawing records
                        msoRecord = null;
                        objRecord = null;
                        }

                    // If this worksheet is just a chart, then the EOF reached
                    // represents the end of the sheet as well as the end of the chart
                    if (sheetBof.isChart())
                        cont = false;
                    }
                else if (type == Type.EOF)
                    cont = false;
                }

            // Restore the file to its accurate position
            excelFile.restorePos();

            // Add any out of bounds cells
            if (outOfBoundsCells.Count > 0)
                handleOutOfBoundsCells();

            // Add all the shared formulas to the sheet as individual formulas
            foreach (SharedFormulaRecord sfr in sharedFormulas)
                {
                Cell[] sfnr = sfr.getFormulas(formattingRecords, nineteenFour);

                for (int sf = 0; sf < sfnr.Length; sf++)
                    addCell(sfnr[sf]);
                }

            // If the last base shared formula wasn't added to the sheet, then
            // revert it to an ordinary formula and add it
            if (!sharedFormulaAdded && sharedFormula != null)
                addCell(revertSharedFormula(sharedFormula));

            // If there is a stray msoDrawing record, then flag to the drawing group
            // that one has been omitted
            if (msoRecord != null && workbook.getDrawingGroup() != null)
                workbook.getDrawingGroup().setDrawingsOmitted(msoRecord, objRecord);

            // Check that the comments hash is empty
            if (comments.Count != 0)
                {
                //logger.warn("Not all comments have a corresponding Note record");
                }
        }