/**
         * 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();
        }
        /**
         * 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();
        }
Beispiel #3
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();
        }
Beispiel #4
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();
        }
        /**
         * Reads in the object record
         *
         * @param objRecord the obj record
         * @param msoRecord the mso drawing record read in earlier
         * @param comments the hash map of comments
         */
        private void handleobjectRecord(ObjRecord objRecord,MsoDrawingRecord msoRecord,Dictionary<uint,Comment> comments)
        {
            if (msoRecord == null)
                {
                //logger.warn("object record is not associated with a drawing record - ignoring");
                return;
                }

            try
                {
                // Handle images
                if (objRecord.getType() == ObjRecord.PICTURE)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    Drawing drawing = new Drawing(msoRecord,
                                                  objRecord,
                                                  drawingData,
                                                  workbook.getDrawingGroup(),
                                                  sheet);
                    drawings.Add(drawing);
                    return;
                    }

                // Handle comments
                if (objRecord.getType() == ObjRecord.EXCELNOTE)
                    {
                    if (drawingData == null)
                        drawingData = new DrawingData();

                    Comment comment = new Comment(msoRecord,
                                                  objRecord,
                                                  drawingData,
                                                  workbook.getDrawingGroup(),
                                                  workbookSettings);

                    // Sometimes Excel writes out Continue records instead of drawing
                    // records, so forcibly hack all of these into a drawing record
                    Record r2 = excelFile.next();
                    if (r2.getType() == Type.MSODRAWING || r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        comment.addMso(mso);
                        r2 = excelFile.next();
                        }
                    Assert.verify(r2.getType() == Type.TXO);
                    TextobjectRecord txo = new TextobjectRecord(r2);
                    comment.setTextobject(txo);

                    r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.CONTINUE);
                    ContinueRecord text = new ContinueRecord(r2);
                    comment.setText(text);

                    r2 = excelFile.next();
                    if (r2.getType() == Type.CONTINUE)
                        {
                        ContinueRecord formatting = new ContinueRecord(r2);
                        comment.setFormatting(formatting);
                        }

                    comments.Add(comment.getObjectId(), comment);
                    return;
                    }

                // Handle combo boxes
                if (objRecord.getType() == ObjRecord.COMBOBOX)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    ComboBox comboBox = new ComboBox(msoRecord,
                                                     objRecord,
                                                     drawingData,
                                                     workbook.getDrawingGroup(),
                                                     workbookSettings);
                    drawings.Add(comboBox);
                    return;
                    }

                // Handle check boxes
                if (objRecord.getType() == ObjRecord.CHECKBOX)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    CheckBox checkBox = new CheckBox(msoRecord,
                                                     objRecord,
                                                     drawingData,
                                                     workbook.getDrawingGroup(),
                                                     workbookSettings);

                    Record r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.MSODRAWING ||
                                  r2.getType() == Type.CONTINUE);
                    if (r2.getType() == Type.MSODRAWING || r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        checkBox.addMso(mso);
                        r2 = excelFile.next();
                        }

                    Assert.verify(r2.getType() == Type.TXO);
                    TextobjectRecord txo = new TextobjectRecord(r2);
                    checkBox.setTextobject(txo);

                    if (txo.getTextLength() == 0)
                        {
                        return;
                        }

                    r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.CONTINUE);
                    ContinueRecord text = new ContinueRecord(r2);
                    checkBox.setText(text);

                    r2 = excelFile.next();
                    if (r2.getType() == Type.CONTINUE)
                        {
                        ContinueRecord formatting = new ContinueRecord(r2);
                        checkBox.setFormatting(formatting);
                        }

                    drawings.Add(checkBox);

                    return;
                    }

                // Handle form buttons
                if (objRecord.getType() == ObjRecord.BUTTON)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    Button button = new Button(msoRecord,
                                               objRecord,
                                               drawingData,
                                               workbook.getDrawingGroup(),
                                               workbookSettings);

                    Record r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.MSODRAWING ||
                                  r2.getType() == Type.CONTINUE);
                    if (r2.getType() == Type.MSODRAWING ||
                        r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        button.addMso(mso);
                        r2 = excelFile.next();
                        }

                    Assert.verify(r2.getType() == Type.TXO);
                    TextobjectRecord txo = new TextobjectRecord(r2);
                    button.setTextobject(txo);

                    r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.CONTINUE);
                    ContinueRecord text = new ContinueRecord(r2);
                    button.setText(text);

                    r2 = excelFile.next();
                    if (r2.getType() == Type.CONTINUE)
                        {
                        ContinueRecord formatting = new ContinueRecord(r2);
                        button.setFormatting(formatting);
                        }

                    drawings.Add(button);

                    return;
                    }

                // Non-supported types which have multiple record types
                if (objRecord.getType() == ObjRecord.TEXT)
                    {
                    //logger.warn(objRecord.getType() + " object on sheet \"" +
                    //            sheet.getName() +
                    //            "\" not supported - omitting");

                    // Still need to add the drawing data to preserve the hierarchy
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();

                        }
                    drawingData.addData(msoRecord.getData());

                    Record r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.MSODRAWING ||
                                  r2.getType() == Type.CONTINUE);
                    if (r2.getType() == Type.MSODRAWING ||
                        r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        drawingData.addRawData(mso.getData());
                        r2 = excelFile.next();
                        }

                    Assert.verify(r2.getType() == Type.TXO);

                    if (workbook.getDrawingGroup() != null) // can be null for Excel 95
                        {
                        workbook.getDrawingGroup().setDrawingsOmitted(msoRecord,
                                                                      objRecord);
                        }

                    return;
                    }

                // Handle other types
                if (objRecord.getType() != ObjRecord.CHART)
                    {
                    //logger.warn(objRecord.getType() + " object on sheet \"" +
                    //            sheet.getName() +
                    //            "\" not supported - omitting");

                    // Still need to add the drawing data to preserve the hierarchy
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    drawingData.addData(msoRecord.getData());

                    if (workbook.getDrawingGroup() != null) // can be null for Excel 95
                        {
                        workbook.getDrawingGroup().setDrawingsOmitted(msoRecord,
                                                                      objRecord);
                        }

                    return;
                    }
                }
            catch (DrawingDataException e)
                {
                //logger.warn(e.Message + "...disabling drawings for the remainder of the workbook");
                workbookSettings.setDrawingsDisabled(true);
                }
        }