Esempio n. 1
0
        /**
         * Gets all the column info records
         *
         * @return the ColumnInfoRecordArray
         */
        public ColumnInfoRecord[] getColumnInfos()
        {
            // Just chuck all the column infos we have into an array
            ColumnInfoRecord[] infos = new ColumnInfoRecord[columnInfosArray.Count];
            for (int i = 0; i < columnInfosArray.Count; i++)
            {
                infos[i] = (ColumnInfoRecord)columnInfosArray[i];
            }

            return(infos);
        }
Esempio n. 2
0
        /**
         * Determines whether or not this cell has been hidden
         *
         * @return TRUE if this cell has been hidden, FALSE otherwise
         */
        public bool isHidden()
        {
            ColumnInfoRecord cir = sheet.getColumnInfo(column);

            if (cir != null && cir.getWidth() == 0)
            {
                return(true);
            }

            RowRecord rr = sheet.getRowInfo(row);

            if (rr != null && (rr.getRowHeight() == 0 || rr.isCollapsed()))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        /**
         * Gets the column width for the specified column
         *
         * @param col the column number
         * @return the column format, or the default format if no override is
         *                 specified
         */
        public CellView getColumnView(int col)
        {
            ColumnInfoRecord cir = getColumnInfo(col);
            CellView         cv  = new CellView();

            if (cir != null)
            {
                cv.setDimension(cir.getWidth() / 256);                 //deprecated
                cv.setSize(cir.getWidth());
                cv.setHidden(cir.getHidden());
                cv.setFormat(formattingRecords.getXFRecord(cir.getXFIndex()));
            }
            else
            {
                cv.setDimension(settings.getDefaultColumnWidth());                 //deprecated
                cv.setSize(settings.getDefaultColumnWidth() * 256);
            }

            return(cv);
        }
Esempio n. 4
0
        /**
         * Reads in the contents of this sheet
         */
        public void readSheet()
        {
            // If this sheet contains only a chart, then set everything to
            // empty and do not bother parsing the sheet
            // Thanks to steve.brophy for spotting this
            if (!sheetBof.isWorksheet())
            {
                numRows = 0;
                numCols = 0;
                cells   = new Cell[0, 0];
                //      return;
            }

            SheetReader reader = new SheetReader(excelFile,
                                                 sharedStrings,
                                                 formattingRecords,
                                                 sheetBof,
                                                 workbookBof,
                                                 nineteenFour,
                                                 workbook,
                                                 startPosition,
                                                 this);

            reader.read();

            // Take stuff that was read in
            numRows            = reader.getNumRows();
            numCols            = reader.getNumCols();
            cells              = reader.getCells();
            rowProperties      = reader.getRowProperties();
            columnInfosArray   = reader.getColumnInfosArray();
            hyperlinks         = reader.getHyperlinks();
            conditionalFormats = reader.getConditionalFormats();
            autoFilter         = reader.getAutoFilter();
            charts             = reader.getCharts();
            drawings           = reader.getDrawings();
            dataValidation     = reader.getDataValidation();
            mergedCells        = reader.getMergedCells();
            settings           = reader.getSettings();
            settings.setHidden(hidden);
            rowBreaks             = reader.getRowBreaks();
            columnBreaks          = reader.getColumnBreaks();
            workspaceOptions      = reader.getWorkspaceOptions();
            plsRecord             = reader.getPLS();
            buttonPropertySet     = reader.getButtonPropertySet();
            maxRowOutlineLevel    = reader.getMaxRowOutlineLevel();
            maxColumnOutlineLevel = reader.getMaxColumnOutlineLevel();

            reader = null;

            //if (!workbookSettings.getGCDisabled())
            //    {
            //    System.gc();
            //    }

            if (columnInfosArray.Count > 0)
            {
                ColumnInfoRecord cir = (ColumnInfoRecord)
                                       columnInfosArray[columnInfosArray.Count - 1];
                columnInfos = new ColumnInfoRecord[cir.getEndColumn() + 1];
            }
            else
            {
                columnInfos = new ColumnInfoRecord[0];
            }

            // Add any local names
            if (localNames != null)
            {
                foreach (NameRecord nr in localNames)
                {
                    if (nr.getBuiltInName() == BuiltInName.PRINT_AREA)
                    {
                        if (nr.getRanges().Length > 0)
                        {
                            NameRecord.NameRange rng = nr.getRanges()[0];
                            settings.setPrintArea(rng.getFirstColumn(),
                                                  rng.getFirstRow(),
                                                  rng.getLastColumn(),
                                                  rng.getLastRow());
                        }
                    }
                    else if (nr.getBuiltInName() == BuiltInName.PRINT_TITLES)
                    {
                        // There can be 1 or 2 entries.
                        // Row entries have hardwired column entries (first and last
                        //  possible column)
                        // Column entries have hardwired row entries (first and last
                        // possible row)
                        for (int i = 0; i < nr.getRanges().Length; i++)
                        {
                            NameRecord.NameRange rng = nr.getRanges()[i];
                            if (rng.getFirstColumn() == 0 && rng.getLastColumn() == 255)
                            {
                                settings.setPrintTitlesRow(rng.getFirstRow(),
                                                           rng.getLastRow());
                            }
                            else
                            {
                                settings.setPrintTitlesCol(rng.getFirstColumn(),
                                                           rng.getLastColumn());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /**
         * Imports a sheet from a different workbook, doing a deep copy
         */
        public void importSheet()
        {
            xfRecords = new Dictionary <int, WritableCellFormat>();
            fonts     = new Dictionary <int, int>();
            formats   = new Dictionary <int, int>();

            deepCopyCells();

            // Copy the column info records
            CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord[] readCirs = fromSheet.getColumnInfos();

            for (int i = 0; i < readCirs.Length; i++)
            {
                CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord rcir = readCirs[i];
                for (int j = rcir.getStartColumn(); j <= rcir.getEndColumn(); j++)
                {
                    ColumnInfoRecord cir = new ColumnInfoRecord(rcir, j);
                    int      xfIndex     = cir.getXfIndex();
                    XFRecord cf          = null;
                    if (!xfRecords.ContainsKey(xfIndex))
                    {
                        // TODO: CML -- what does THIS actually achieve unless it has side-effects?
                        CellFormat         readFormat = fromSheet.getColumnView(j).getFormat();
                        WritableCellFormat wcf        = copyCellFormat(readFormat);
                    }
                    else
                    {
                        cf = xfRecords[xfIndex];
                    }

                    cir.setCellFormat(cf);
                    cir.setHidden(rcir.getHidden());
                    columnFormats.Add(cir);
                }
            }

            // Copy the hyperlinks
            Hyperlink[] hls = fromSheet.getHyperlinks();
            for (int i = 0; i < hls.Length; i++)
            {
                WritableHyperlink hr = new WritableHyperlink(hls[i], toSheet);
                hyperlinks.Add(hr);
            }

            // Copy the merged cells
            Range[] merged = fromSheet.getMergedCells();

            for (int i = 0; i < merged.Length; i++)
            {
                mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet));
            }

            // Copy the row properties
            try
            {
                CSharpJExcel.Jxl.Read.Biff.RowRecord[] rowprops = fromSheet.getRowProperties();

                for (int i = 0; i < rowprops.Length; i++)
                {
                    RowRecord rr     = toSheet.getRowRecord(rowprops[i].getRowNumber());
                    XFRecord  format = null;
                    CSharpJExcel.Jxl.Read.Biff.RowRecord rowrec = rowprops[i];
                    if (rowrec.hasDefaultFormat())
                    {
                        if (!xfRecords.ContainsKey(rowrec.getXFIndex()))
                        {
                            int                rownum     = rowrec.getRowNumber();
                            CellFormat         readFormat = fromSheet.getRowView(rownum).getFormat();
                            WritableCellFormat wcf        = copyCellFormat(readFormat);
                        }
                        else
                        {
                            format = xfRecords[rowrec.getXFIndex()];
                        }
                    }

                    rr.setRowDetails(rowrec.getRowHeight(),
                                     rowrec.matchesDefaultFontHeight(),
                                     rowrec.isCollapsed(),
                                     rowrec.getOutlineLevel(),
                                     rowrec.getGroupStart(),
                                     format);
                    numRows = System.Math.Max(numRows, rowprops[i].getRowNumber() + 1);
                }
            }
            catch (RowsExceededException e)
            {
                // Handle the rows exceeded exception - this cannot occur since
                // the sheet we are copying from will have a valid number of rows
                Assert.verify(false);
            }

            // Copy the headers and footers
            //    sheetWriter.setHeader(new HeaderRecord(si.getHeader()));
            //    sheetWriter.setFooter(new FooterRecord(si.getFooter()));

            // Copy the page breaks
            int[] rowbreaks = fromSheet.getRowPageBreaks();

            if (rowbreaks != null)
            {
                for (int i = 0; i < rowbreaks.Length; i++)
                {
                    rowBreaks.Add(rowbreaks[i]);
                }
            }

            int[] columnbreaks = fromSheet.getColumnPageBreaks();

            if (columnbreaks != null)
            {
                for (int i = 0; i < columnbreaks.Length; i++)
                {
                    columnBreaks.Add(columnbreaks[i]);
                }
            }

            // Copy the charts
            Chart[] fromCharts = fromSheet.getCharts();
            if (fromCharts != null && fromCharts.Length > 0)
            {
                //logger.warn("Importing of charts is not supported");

                /*
                 * sheetWriter.setCharts(fromSheet.getCharts());
                 * IndexMapping xfMapping = new IndexMapping(200);
                 * for (Iterator i = xfRecords.keySet().iterator(); i.hasNext();)
                 * {
                 * Integer key = (Integer) i.next();
                 * XFRecord xfmapping = (XFRecord) xfRecords[key);
                 * xfMapping.setMapping(key, xfmapping.getXFIndex());
                 * }
                 *
                 * IndexMapping fontMapping = new IndexMapping(200);
                 * for (Iterator i = fonts.keySet().iterator(); i.hasNext();)
                 * {
                 * Integer key = (Integer) i.next();
                 * Integer fontmap = (Integer) fonts[key);
                 * fontMapping.setMapping(key, fontmap);
                 * }
                 *
                 * IndexMapping formatMapping = new IndexMapping(200);
                 * for (Iterator i = formats.keySet().iterator(); i.hasNext();)
                 * {
                 * Integer key = (Integer) i.next();
                 * Integer formatmap = (Integer) formats[key);
                 * formatMapping.setMapping(key, formatmap);
                 * }
                 *
                 * // Now reuse the rationalization feature on each chart  to
                 * // handle the new fonts
                 * for (int i = 0; i < fromCharts.Length ; i++)
                 * {
                 * fromCharts[i].rationalize(xfMapping, fontMapping, formatMapping);
                 * }
                 */
            }

            // Copy the drawings
            DrawingGroupObject[] dr = fromSheet.getDrawings();

            // Make sure the destination workbook has a drawing group
            // created in it
            if (dr.Length > 0 && toSheet.getWorkbook().getDrawingGroup() == null)
            {
                toSheet.getWorkbook().createDrawingGroup();
            }

            for (int i = 0; i < dr.Length; i++)
            {
                if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Drawing)
                {
                    WritableImage wi = new WritableImage
                                           (dr[i].getX(), dr[i].getY(),
                                           dr[i].getWidth(), dr[i].getHeight(),
                                           dr[i].getImageData());
                    toSheet.getWorkbook().addDrawing(wi);
                    drawings.Add(wi);
                    images.Add(wi);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Comment)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.Comment c = new CSharpJExcel.Jxl.Biff.Drawing.Comment(dr[i],
                                                                                                        toSheet.getWorkbook().getDrawingGroup(),
                                                                                                        workbookSettings);
                    drawings.Add(c);

                    // Set up the reference on the cell value
                    CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(), c.getRow());
                    Assert.verify(cv.getCellFeatures() != null);
                    cv.getWritableCellFeatures().setCommentDrawing(c);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Button)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.Button b = new CSharpJExcel.Jxl.Biff.Drawing.Button(dr[i],
                                                                                                      toSheet.getWorkbook().getDrawingGroup(),
                                                                                                      workbookSettings);
                    drawings.Add(b);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.ComboBox)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.ComboBox cb = new CSharpJExcel.Jxl.Biff.Drawing.ComboBox(dr[i],
                                                                                                           toSheet.getWorkbook().getDrawingGroup(),
                                                                                                           workbookSettings);
                    drawings.Add(cb);
                }
            }

            // Copy the data validations
            DataValidation rdv = fromSheet.getDataValidation();

            if (rdv != null)
            {
                dataValidation = new DataValidation(rdv,
                                                    toSheet.getWorkbook(),
                                                    toSheet.getWorkbook(),
                                                    workbookSettings);
                uint objid = dataValidation.getComboBoxObjectId();
                if (objid != 0)
                {
                    comboBox = (ComboBox)drawings[(int)objid];
                }
            }

            // Copy the workspace options
            sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions());

            // Set a flag to indicate if it contains a chart only
            if (fromSheet.getSheetBof().isChart())
            {
                chartOnly = true;
                sheetWriter.setChartOnly();
            }

            // Copy the environment specific print record
            if (fromSheet.getPLS() != null)
            {
                if (fromSheet.getWorkbookBof().isBiff7())
                {
                    //logger.warn("Cannot copy Biff7 print settings record - ignoring");
                }
                else
                {
                    plsRecord = new PLSRecord(fromSheet.getPLS());
                }
            }

            // Copy the button property set
            if (fromSheet.getButtonPropertySet() != null)
            {
                buttonPropertySet = new ButtonPropertySetRecord
                                        (fromSheet.getButtonPropertySet());
            }

            importNames();

            // Copy the outline levels
            maxRowOutlineLevel    = fromSheet.getMaxRowOutlineLevel();
            maxColumnOutlineLevel = fromSheet.getMaxColumnOutlineLevel();
        }
Esempio n. 6
0
        /**
         * Copies a sheet from a read-only version to the writable version.
         * Performs shallow copies
         */
        public void copySheet()
        {
            shallowCopyCells();

            // Copy the column info records
            CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord[] readCirs = fromSheet.getColumnInfos();

            for (int i = 0; i < readCirs.Length; i++)
            {
                CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord rcir = readCirs[i];
                for (int j = rcir.getStartColumn(); j <= rcir.getEndColumn(); j++)
                {
                    ColumnInfoRecord cir = new ColumnInfoRecord(rcir, j,
                                                                formatRecords);
                    cir.setHidden(rcir.getHidden());
                    columnFormats.Add(cir);
                }
            }

            // Copy the hyperlinks
            Hyperlink[] hls = fromSheet.getHyperlinks();
            for (int i = 0; i < hls.Length; i++)
            {
                WritableHyperlink hr = new WritableHyperlink
                                           (hls[i], toSheet);
                hyperlinks.Add(hr);
            }

            // Copy the merged cells
            Range[] merged = fromSheet.getMergedCells();

            for (int i = 0; i < merged.Length; i++)
            {
                mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet));
            }

            // Copy the row properties
            try
            {
                CSharpJExcel.Jxl.Read.Biff.RowRecord[] rowprops = fromSheet.getRowProperties();

                for (int i = 0; i < rowprops.Length; i++)
                {
                    RowRecord rr     = toSheet.getRowRecord(rowprops[i].getRowNumber());
                    XFRecord  format = rowprops[i].hasDefaultFormat() ?
                                       formatRecords.getXFRecord(rowprops[i].getXFIndex()) : null;
                    rr.setRowDetails(rowprops[i].getRowHeight(),
                                     rowprops[i].matchesDefaultFontHeight(),
                                     rowprops[i].isCollapsed(),
                                     rowprops[i].getOutlineLevel(),
                                     rowprops[i].getGroupStart(),
                                     format);
                    numRows = System.Math.Max(numRows, rowprops[i].getRowNumber() + 1);
                }
            }
            catch (RowsExceededException e)
            {
                // Handle the rows exceeded exception - this cannot occur since
                // the sheet we are copying from will have a valid number of rows
                Assert.verify(false);
            }

            // Copy the headers and footers
            //    sheetWriter.setHeader(new HeaderRecord(si.getHeader()));
            //    sheetWriter.setFooter(new FooterRecord(si.getFooter()));

            // Copy the page breaks
            int[] rowbreaks = fromSheet.getRowPageBreaks();

            if (rowbreaks != null)
            {
                for (int i = 0; i < rowbreaks.Length; i++)
                {
                    rowBreaks.Add(rowbreaks[i]);
                }
            }

            int[] columnbreaks = fromSheet.getColumnPageBreaks();

            if (columnbreaks != null)
            {
                for (int i = 0; i < columnbreaks.Length; i++)
                {
                    columnBreaks.Add(columnbreaks[i]);
                }
            }

            // Copy the charts
            sheetWriter.setCharts(fromSheet.getCharts());

            // Copy the drawings
            DrawingGroupObject[] dr = fromSheet.getDrawings();
            for (int i = 0; i < dr.Length; i++)
            {
                if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Drawing)
                {
                    WritableImage wi = new WritableImage
                                           (dr[i], toSheet.getWorkbook().getDrawingGroup());
                    drawings.Add(wi);
                    images.Add(wi);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Comment)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.Comment c =
                        new CSharpJExcel.Jxl.Biff.Drawing.Comment(dr[i],
                                                                  toSheet.getWorkbook().getDrawingGroup(),
                                                                  workbookSettings);
                    drawings.Add(c);

                    // Set up the reference on the cell value
                    CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(),
                                                                      c.getRow());
                    Assert.verify(cv.getCellFeatures() != null);
                    cv.getWritableCellFeatures().setCommentDrawing(c);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Button)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.Button b =
                        new CSharpJExcel.Jxl.Biff.Drawing.Button
                            (dr[i],
                            toSheet.getWorkbook().getDrawingGroup(),
                            workbookSettings);
                    drawings.Add(b);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.ComboBox)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.ComboBox cb =
                        new CSharpJExcel.Jxl.Biff.Drawing.ComboBox
                            (dr[i],
                            toSheet.getWorkbook().getDrawingGroup(),
                            workbookSettings);
                    drawings.Add(cb);
                }
                else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.CheckBox)
                {
                    CSharpJExcel.Jxl.Biff.Drawing.CheckBox cb =
                        new CSharpJExcel.Jxl.Biff.Drawing.CheckBox
                            (dr[i],
                            toSheet.getWorkbook().getDrawingGroup(),
                            workbookSettings);
                    drawings.Add(cb);
                }
            }

            // Copy the data validations
            DataValidation rdv = fromSheet.getDataValidation();

            if (rdv != null)
            {
                dataValidation = new DataValidation(rdv,
                                                    toSheet.getWorkbook(),
                                                    toSheet.getWorkbook(),
                                                    workbookSettings);
                uint objid = dataValidation.getComboBoxObjectId();
                if (objid != 0)
                {
                    comboBox = (ComboBox)drawings[(int)objid];
                }
            }

            // Copy the conditional formats
            ConditionalFormat[] cf = fromSheet.getConditionalFormats();
            if (cf.Length > 0)
            {
                for (int i = 0; i < cf.Length; i++)
                {
                    conditionalFormats.Add(cf[i]);
                }
            }

            // Get the autofilter
            autoFilter = fromSheet.getAutoFilter();

            // Copy the workspace options
            sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions());

            // Set a flag to indicate if it contains a chart only
            if (fromSheet.getSheetBof().isChart())
            {
                chartOnly = true;
                sheetWriter.setChartOnly();
            }

            // Copy the environment specific print record
            if (fromSheet.getPLS() != null)
            {
                if (fromSheet.getWorkbookBof().isBiff7())
                {
                    //logger.warn("Cannot copy Biff7 print settings record - ignoring");
                }
                else
                {
                    plsRecord = new PLSRecord(fromSheet.getPLS());
                }
            }

            // Copy the button property set
            if (fromSheet.getButtonPropertySet() != null)
            {
                buttonPropertySet = new ButtonPropertySetRecord
                                        (fromSheet.getButtonPropertySet());
            }

            // Copy the outline levels
            maxRowOutlineLevel    = fromSheet.getMaxRowOutlineLevel();
            maxColumnOutlineLevel = fromSheet.getMaxColumnOutlineLevel();
        }
        /**
         * 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");
                }
        }