/// <summary>
        /// Attempts to merge the col info record at the specified index
        /// with either or both of its neighbours
        /// </summary>
        /// <param name="colInfoIx">The col info ix.</param>
        private void AttemptMergeColInfoRecords(int colInfoIx)
        {
            int nRecords = records.Count;

            if (colInfoIx < 0 || colInfoIx >= nRecords)
            {
                throw new ArgumentException("colInfoIx " + colInfoIx
                                            + " is out of range (0.." + (nRecords - 1) + ")");
            }
            ColumnInfoRecord currentCol = GetColInfo(colInfoIx);
            int nextIx = colInfoIx + 1;

            if (nextIx < nRecords)
            {
                if (MergeColInfoRecords(currentCol, GetColInfo(nextIx)))
                {
                    records.RemoveAt(nextIx);
                }
            }
            if (colInfoIx > 0)
            {
                if (MergeColInfoRecords(GetColInfo(colInfoIx - 1), currentCol))
                {
                    records.RemoveAt(colInfoIx);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets all adjacent columns of the same outline level to the specified hidden status.
        /// </summary>
        /// <param name="pIdx">the col info index of the start of the outline group.</param>
        /// <param name="level">The level.</param>
        /// <param name="hidden">The hidden.</param>
        /// <returns>the column index of the last column in the outline group</returns>
        private int SetGroupHidden(int pIdx, int level, bool hidden)
        {
            int idx = pIdx;
            ColumnInfoRecord columnInfo = GetColInfo(idx);

            while (idx < records.Count)
            {
                columnInfo.IsHidden = (hidden);
                if (idx + 1 < records.Count)
                {
                    ColumnInfoRecord nextColumnInfo = GetColInfo(idx + 1);
                    if (!columnInfo.IsAdjacentBefore(nextColumnInfo))
                    {
                        break;
                    }
                    if (nextColumnInfo.OutlineLevel < level)
                    {
                        break;
                    }
                    columnInfo = nextColumnInfo;
                }
                idx++;
            }
            return(columnInfo.LastColumn);
        }
        /// <summary>
        /// Finds the start of column outline group.
        /// </summary>
        /// <param name="idx">The idx.</param>
        /// <returns></returns>
        public int FindStartOfColumnOutlineGroup(int idx)
        {
            // Find the start of the Group.
            ColumnInfoRecord columnInfo = (ColumnInfoRecord)records[idx];
            int level = columnInfo.OutlineLevel;

            while (idx != 0)
            {
                ColumnInfoRecord prevColumnInfo = (ColumnInfoRecord)records[idx - 1];
                if (columnInfo.FirstColumn - 1 == prevColumnInfo.LastColumn)
                {
                    if (prevColumnInfo.OutlineLevel < level)
                    {
                        break;
                    }
                    idx--;
                    columnInfo = prevColumnInfo;
                }
                else
                {
                    break;
                }
            }

            return(idx);
        }
        /// <summary>
        /// Finds the end of column outline group.
        /// </summary>
        /// <param name="idx">The idx.</param>
        /// <returns></returns>
        public int FindEndOfColumnOutlineGroup(int idx)
        {
            // Find the end of the Group.
            ColumnInfoRecord columnInfo = (ColumnInfoRecord)records[idx];
            int level = columnInfo.OutlineLevel;

            while (idx < records.Count - 1)
            {
                ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord)records[idx + 1];
                if (columnInfo.LastColumn + 1 == nextColumnInfo.FirstColumn)
                {
                    if (nextColumnInfo.OutlineLevel < level)
                    {
                        break;
                    }
                    idx++;
                    columnInfo = nextColumnInfo;
                }
                else
                {
                    break;
                }
            }

            return(idx);
        }
Ejemplo n.º 5
0
        private int FindColInfoIdx(int columnIx, int fromColInfoIdx)
        {
            if (columnIx < 0)
            {
                throw new ArgumentException("column parameter out of range: " + columnIx);
            }
            if (fromColInfoIdx < 0)
            {
                throw new ArgumentException("fromIdx parameter out of range: " + fromColInfoIdx);
            }

            for (int k = fromColInfoIdx; k < records.Count; k++)
            {
                ColumnInfoRecord ci = GetColInfo(k);
                if (ci.ContainsColumn(columnIx))
                {
                    return(k);
                }
                if (ci.FirstColumn > columnIx)
                {
                    break;
                }
            }
            return(-1);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Collapses the col info records.
        /// </summary>
        /// <param name="columnIdx">The column index.</param>
        public void CollapseColInfoRecords(int columnIdx)
        {
            if (columnIdx == 0)
            {
                return;
            }
            ColumnInfoRecord previousCol     = (ColumnInfoRecord)records[columnIdx - 1];
            ColumnInfoRecord currentCol      = (ColumnInfoRecord)records[columnIdx];
            bool             adjacentColumns = previousCol.LastColumn == currentCol.FirstColumn - 1;

            if (!adjacentColumns)
            {
                return;
            }

            bool columnsMatch =
                previousCol.XFIndex == currentCol.XFIndex &&
                previousCol.Options == currentCol.Options &&
                previousCol.ColumnWidth == currentCol.ColumnWidth;

            if (columnsMatch)
            {
                previousCol.LastColumn = currentCol.LastColumn;
                records.Remove(columnIdx);
            }
        }
Ejemplo n.º 7
0
        public void TestGetCellWidth()
        {
            InternalSheet    sheet = InternalSheet.CreateSheet();
            ColumnInfoRecord nci   = new ColumnInfoRecord();

            // Prepare test model
            nci.FirstColumn = 5;
            nci.LastColumn  = 10;
            nci.ColumnWidth = 100;


            sheet._columnInfos.InsertColumn(nci);

            Assert.AreEqual(100, sheet.GetColumnWidth(5));
            Assert.AreEqual(100, sheet.GetColumnWidth(6));
            Assert.AreEqual(100, sheet.GetColumnWidth(7));
            Assert.AreEqual(100, sheet.GetColumnWidth(8));
            Assert.AreEqual(100, sheet.GetColumnWidth(9));
            Assert.AreEqual(100, sheet.GetColumnWidth(10));

            sheet.SetColumnWidth(6, 200);

            Assert.AreEqual(100, sheet.GetColumnWidth(5));
            Assert.AreEqual(200, sheet.GetColumnWidth(6));
            Assert.AreEqual(100, sheet.GetColumnWidth(7));
            Assert.AreEqual(100, sheet.GetColumnWidth(8));
            Assert.AreEqual(100, sheet.GetColumnWidth(9));
            Assert.AreEqual(100, sheet.GetColumnWidth(10));
        }
        /**
         * Sets all non null fields into the <c>ci</c> parameter.
         */

        private void SetColumnInfoFields(ColumnInfoRecord ci, short xfStyle, short width, int level, bool hidden, bool collapsed)
        {
            ci.XFIndex      = (xfStyle);
            ci.ColumnWidth  = (width);
            ci.OutlineLevel = (short)level;
            ci.IsHidden     = (hidden);
            ci.IsCollapsed  = (collapsed);
        }
Ejemplo n.º 9
0
        private static ColumnInfoRecord CreateColInfo(int firstCol, int lastCol)
        {
            ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord();

            columnInfoRecord.FirstColumn = ((short)firstCol);
            columnInfoRecord.LastColumn  = ((short)lastCol);
            return(columnInfoRecord);
        }
Ejemplo n.º 10
0
        /**
         * merges two column info records (if they are adjacent and have the same formatting, etc)
         * @return <c>false</c> if the two column records could not be merged
         */

        private static bool MergeColInfoRecords(ColumnInfoRecord ciA, ColumnInfoRecord ciB)
        {
            if (ciA.IsAdjacentBefore(ciB) && ciA.FormatMatches(ciB))
            {
                ciA.LastColumn = ciB.LastColumn;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 11
0
        public void TestOneReservedByte()
        {
            byte[]            inpData = HexRead.ReadFromString("7D 00 0B 00 00 00 00 00 24 02 0F 00 00 00 01");
            byte[]            outData = HexRead.ReadFromString("7D 00 0C 00 00 00 00 00 24 02 0F 00 00 00 01 00");
            RecordInputStream in1     = TestcaseRecordInputStream.Create(inpData);
            ColumnInfoRecord  cir     = new ColumnInfoRecord(in1);

            Assert.AreEqual(0, in1.Remaining);
            Assert.IsTrue(Arrays.Equals(outData, cir.Serialize()));
        }
Ejemplo n.º 12
0
        private static void ConfirmCIR(ColumnInfoRecord[] cirs,
                                       int ix, int startColIx, int endColIx, int level, bool isHidden, bool isCollapsed)
        {
            ColumnInfoRecord cir = cirs[ix];

            Assert.AreEqual(startColIx, cir.FirstColumn, "startColIx");
            Assert.AreEqual(endColIx, cir.LastColumn, "endColIx");
            Assert.AreEqual(level, cir.OutlineLevel, "level");
            Assert.AreEqual(isHidden, cir.IsHidden, "hidden");
            Assert.AreEqual(isCollapsed, cir.IsCollapsed, "collapsed");
        }
Ejemplo n.º 13
0
            public static ColumnInfoRecord[] GetRecords(ColumnInfoRecordsAggregate agg)
            {
                CIRCollector circ = new CIRCollector();

                agg.VisitContainedRecords(circ);
                ArrayList list = circ._list;

                ColumnInfoRecord[] result = new ColumnInfoRecord[list.Count];
                result = (ColumnInfoRecord[])list.ToArray(typeof(ColumnInfoRecord));
                return(result);
            }
        /**
         * Performs a deep Clone of the record
         */
        public Object Clone()
        {
            ColumnInfoRecordsAggregate rec = new ColumnInfoRecordsAggregate();

            for (int k = 0; k < records.Count; k++)
            {
                ColumnInfoRecord ci = (ColumnInfoRecord)records[k];
                ci = (ColumnInfoRecord)ci.Clone();
            }
            return(rec);
        }
Ejemplo n.º 15
0
        public int GetOutlineLevel(int columnIndex)
        {
            ColumnInfoRecord ci = FindColumnInfo(columnIndex);

            if (ci != null)
            {
                return(ci.OutlineLevel);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Finds the ColumnInfoRecord
        ///  which contains the specified columnIndex
        /// </summary>
        /// <param name="columnIndex">index of the column (not the index of the ColumnInfoRecord)</param>
        /// <returns>        /// <c>null</c>
        ///  if no column info found for the specified column
        ///  </returns>
        public ColumnInfoRecord FindColumnInfo(int columnIndex)
        {
            int nInfos = records.Count;

            for (int i = 0; i < nInfos; i++)
            {
                ColumnInfoRecord ci = GetColInfo(i);
                if (ci.ContainsColumn(columnIndex))
                {
                    return(ci);
                }
            }
            return(null);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Determines whether [is column group collapsed] [the specified idx].
        /// </summary>
        /// <param name="idx">The idx.</param>
        /// <returns>
        ///     <c>true</c> if [is column group collapsed] [the specified idx]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsColumnGroupCollapsed(int idx)
        {
            int endOfOutlineGroupIdx = FindEndOfColumnOutlineGroup(idx);
            int nextColInfoIx        = endOfOutlineGroupIdx + 1;

            if (nextColInfoIx >= records.Count)
            {
                return(false);
            }
            ColumnInfoRecord nextColInfo = GetColInfo(nextColInfoIx);

            if (!GetColInfo(endOfOutlineGroupIdx).IsAdjacentBefore(nextColInfo))
            {
                return(false);
            }
            return(nextColInfo.IsCollapsed);
        }
Ejemplo n.º 18
0
        public void TestBasic()
        {
            byte[] data = HexRead.ReadFromString("7D 00 0C 00 14 00 9B 00 C7 19 0F 00 01 13 00 00");

            RecordInputStream in1 = TestcaseRecordInputStream.Create(data);
            ColumnInfoRecord  cir = new ColumnInfoRecord(in1);

            Assert.AreEqual(0, in1.Remaining);

            Assert.AreEqual(20, cir.FirstColumn);
            Assert.AreEqual(155, cir.LastColumn);
            Assert.AreEqual(6599, cir.ColumnWidth);
            Assert.AreEqual(15, cir.XFIndex);
            Assert.AreEqual(true, cir.IsHidden);
            Assert.AreEqual(3, cir.OutlineLevel);
            Assert.AreEqual(true, cir.IsCollapsed);
            Assert.IsTrue(Arrays.Equals(data, cir.Serialize()));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Expands the column.
        /// </summary>
        /// <param name="columnNumber">The column number.</param>
        public void ExpandColumn(int columnNumber)
        {
            int idx = FindColInfoIdx(columnNumber, 0);

            if (idx == -1)
            {
                return;
            }

            // If it is already exapanded do nothing.
            if (!IsColumnGroupCollapsed(idx))
            {
                return;
            }

            // Find the start of the Group.
            int startIdx = FindStartOfColumnOutlineGroup(idx);
            ColumnInfoRecord columnInfo = GetColInfo(startIdx);

            // Find the end of the Group.
            int endIdx = FindEndOfColumnOutlineGroup(idx);
            ColumnInfoRecord endColumnInfo = GetColInfo(endIdx);

            // expand:
            // colapsed bit must be UnSet
            // hidden bit Gets UnSet _if_ surrounding Groups are expanded you can determine
            //   this by looking at the hidden bit of the enclosing Group.  You will have
            //   to look at the start and the end of the current Group to determine which
            //   is the enclosing Group
            // hidden bit only is altered for this outline level.  ie.  don't Uncollapse contained Groups
            if (!IsColumnGroupHiddenByParent(idx))
            {
                for (int i = startIdx; i <= endIdx; i++)
                {
                    if (columnInfo.OutlineLevel == GetColInfo(i).OutlineLevel)
                    {
                        GetColInfo(i).IsHidden = false;
                    }
                }
            }

            // Write collapse field
            SetColumn(columnInfo.LastColumn + 1, null, null, null, null, false);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Collapses the column.
        /// </summary>
        /// <param name="columnNumber">The column number.</param>
        public void CollapseColumn(int columnNumber)
        {
            int idx = FindColInfoIdx(columnNumber, 0);

            if (idx == -1)
            {
                return;
            }

            // Find the start of the group.
            int groupStartColInfoIx     = FindStartOfColumnOutlineGroup(idx);
            ColumnInfoRecord columnInfo = GetColInfo(groupStartColInfoIx);

            // Hide all the columns until the end of the group
            int lastColIx = SetGroupHidden(groupStartColInfoIx, columnInfo.OutlineLevel, true);

            // Write collapse field
            SetColumn(lastColIx + 1, null, null, null, null, true);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Visit each of the atomic BIFF records contained in this {@link RecordAggregate} in the order
        /// that they should be written to file.  Implementors may or may not return the actual
        /// Records being used to manage POI's internal implementation.  Callers should not
        /// assume either way, and therefore only attempt to modify those Records after cloning
        /// </summary>
        /// <param name="rv"></param>
        public override void VisitContainedRecords(RecordVisitor rv)
        {
            int nItems = records.Count;

            if (nItems < 1)
            {
                return;
            }
            ColumnInfoRecord cirPrev = null;

            for (int i = 0; i < nItems; i++)
            {
                ColumnInfoRecord cir = (ColumnInfoRecord)records[i];
                rv.VisitRecord(cir);
                if (cirPrev != null && CIRComparator.CompareColInfos(cirPrev, cir) > 0)
                {
                    // Excel probably wouldn't mind, but there is much logic in this class
                    // that assumes the column info records are kept in order
                    throw new InvalidOperationException("Column info records are out of order");
                }
                cirPrev = cir;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Determines whether [is column group hidden by parent] [the specified idx].
        /// </summary>
        /// <param name="idx">The idx.</param>
        /// <returns>
        ///     <c>true</c> if [is column group hidden by parent] [the specified idx]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsColumnGroupHiddenByParent(int idx)
        {
            // Look out outline details of end
            int  endLevel             = 0;
            bool endHidden            = false;
            int  endOfOutlineGroupIdx = FindEndOfColumnOutlineGroup(idx);

            if (endOfOutlineGroupIdx < records.Count)
            {
                ColumnInfoRecord nextInfo = GetColInfo(endOfOutlineGroupIdx + 1);
                if (GetColInfo(endOfOutlineGroupIdx).IsAdjacentBefore(nextInfo))
                {
                    endLevel  = nextInfo.OutlineLevel;
                    endHidden = nextInfo.IsHidden;
                }
            }
            // Look out outline details of start
            int  startLevel             = 0;
            bool startHidden            = false;
            int  startOfOutlineGroupIdx = FindStartOfColumnOutlineGroup(idx);

            if (startOfOutlineGroupIdx > 0)
            {
                ColumnInfoRecord prevInfo = GetColInfo(startOfOutlineGroupIdx - 1);
                if (prevInfo.IsAdjacentBefore(GetColInfo(startOfOutlineGroupIdx)))
                {
                    startLevel  = prevInfo.OutlineLevel;
                    startHidden = prevInfo.IsHidden;
                }
            }
            if (endLevel > startLevel)
            {
                return(endHidden);
            }
            return(startHidden);
        }
Ejemplo n.º 23
0
        /**
         * Sets all non null fields into the <c>ci</c> parameter.
         */

        private static void SetColumnInfoFields(ColumnInfoRecord ci, short?xfStyle, int?width,
                                                int?level, Boolean?hidden, Boolean?collapsed)
        {
            if (xfStyle != null)
            {
                ci.XFIndex = Convert.ToInt16(xfStyle, CultureInfo.InvariantCulture);
            }
            if (width != null)
            {
                ci.ColumnWidth = Convert.ToInt32(width, CultureInfo.InvariantCulture);
            }
            if (level != null)
            {
                ci.OutlineLevel = (short)level;
            }
            if (hidden != null)
            {
                ci.IsHidden = Convert.ToBoolean(hidden, CultureInfo.InvariantCulture);
            }
            if (collapsed != null)
            {
                ci.IsCollapsed = Convert.ToBoolean(collapsed, CultureInfo.InvariantCulture);
            }
        }
Ejemplo n.º 24
0
        public void TestZeroResevedBytes_bug48332()
        {
            // Taken from bugzilla attachment 24661 (offset 0x1E73)
            byte[] inpData = HexRead.ReadFromString("7D 00 0A 00 00 00 00 00 D5 19 0F 00 02 00");
            byte[] outData = HexRead.ReadFromString("7D 00 0C 00 00 00 00 00 D5 19 0F 00 02 00 00 00");

            RecordInputStream in1 = TestcaseRecordInputStream.Create(inpData);
            ColumnInfoRecord  cir;

            try
            {
                cir = new ColumnInfoRecord(in1);
            }
            catch (RuntimeException e)
            {
                if (e.Message.Equals("Unusual record size remaining=(0)"))
                {
                    throw new AssertionException("Identified bug 48332");
                }
                throw e;
            }
            Assert.AreEqual(0, in1.Remaining);
            Assert.IsTrue(Arrays.Equals(outData, cir.Serialize()));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnInfoRecordsAggregate"/> class.
        /// </summary>
        /// <param name="rs">The rs.</param>
        public ColumnInfoRecordsAggregate(RecordStream rs) : this()
        {
            bool             isInOrder = true;
            ColumnInfoRecord cirPrev   = null;

            while (rs.PeekNextClass() == typeof(ColumnInfoRecord))
            {
                ColumnInfoRecord cir = (ColumnInfoRecord)rs.GetNext();
                records.Add(cir);
                if (cirPrev != null && CIRComparator.CompareColInfos(cirPrev, cir) > 0)
                {
                    isInOrder = false;
                }
                cirPrev = cir;
            }
            if (records.Count < 1)
            {
                throw new InvalidOperationException("No column info records found");
            }
            if (!isInOrder)
            {
                records.Sort(CIRComparator.instance);
            }
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Inserts a column into the aggregate (at the end of the list).
 /// </summary>
 /// <param name="col">The column.</param>
 public void InsertColumn(ColumnInfoRecord col)
 {
     records.Add(col);
     records.Sort(CIRComparator.instance);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Inserts a column into the aggregate (at the position specified
 /// by index
 /// </summary>
 /// <param name="idx">The index.</param>
 /// <param name="col">The columninfo.</param>
 public void InsertColumn(int idx, ColumnInfoRecord col)
 {
     records.Insert(idx, col);
 }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
 private ColumnInfoRecord CopyColInfo(ColumnInfoRecord ci)
 {
     return((ColumnInfoRecord)ci.Clone());
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Sets the column.
        /// </summary>
        /// <param name="targetColumnIx">The target column ix.</param>
        /// <param name="xfIndex">Index of the xf.</param>
        /// <param name="width">The width.</param>
        /// <param name="level">The level.</param>
        /// <param name="hidden">The hidden.</param>
        /// <param name="collapsed">The collapsed.</param>
        public void SetColumn(int targetColumnIx, short?xfIndex, int?width, int?level, bool?hidden, bool?collapsed)
        {
            ColumnInfoRecord ci = null;
            int k = 0;

            for (k = 0; k < records.Count; k++)
            {
                ColumnInfoRecord tci = (ColumnInfoRecord)records[k];
                if (tci.ContainsColumn(targetColumnIx))
                {
                    ci = tci;
                    break;
                }
                if (tci.FirstColumn > targetColumnIx)
                {
                    // call targetColumnIx infos after k are for later targetColumnIxs
                    break; // exit now so k will be the correct insert pos
                }
            }

            if (ci == null)
            {
                // okay so there IsN'T a targetColumnIx info record that cover's this targetColumnIx so lets Create one!
                ColumnInfoRecord nci = new ColumnInfoRecord();

                nci.FirstColumn = targetColumnIx;
                nci.LastColumn  = targetColumnIx;
                SetColumnInfoFields(nci, xfIndex, width, level, hidden, collapsed);
                InsertColumn(k, nci);
                AttemptMergeColInfoRecords(k);
                return;
            }

            bool styleChanged          = ci.XFIndex != xfIndex;
            bool widthChanged          = ci.ColumnWidth != width;
            bool levelChanged          = ci.OutlineLevel != level;
            bool hiddenChanged         = ci.IsHidden != hidden;
            bool collapsedChanged      = ci.IsCollapsed != collapsed;
            bool targetColumnIxChanged = styleChanged || widthChanged || levelChanged || hiddenChanged || collapsedChanged;

            if (!targetColumnIxChanged)
            {
                // do nothing...nothing Changed.
                return;
            }
            if ((ci.FirstColumn == targetColumnIx) &&
                (ci.LastColumn == targetColumnIx))
            {                               // if its only for this cell then
                // ColumnInfo ci for a single column, the target column
                SetColumnInfoFields(ci, xfIndex, width, level, hidden, collapsed);
                AttemptMergeColInfoRecords(k);
                return;
            }
            if ((ci.FirstColumn == targetColumnIx) ||
                (ci.LastColumn == targetColumnIx))
            {
                // The target column is at either end of the multi-column ColumnInfo ci
                // we'll just divide the info and create a new one
                if (ci.FirstColumn == targetColumnIx)
                {
                    ci.FirstColumn = targetColumnIx + 1;
                }
                else
                {
                    ci.LastColumn = targetColumnIx - 1;
                    k++; // adjust insert pos to insert after
                }
                ColumnInfoRecord nci = CopyColInfo(ci);

                nci.FirstColumn = targetColumnIx;
                nci.LastColumn  = targetColumnIx;

                SetColumnInfoFields(nci, xfIndex, width, level, hidden, collapsed);

                InsertColumn(k, nci);
                AttemptMergeColInfoRecords(k);
            }
            else
            {
                //split to 3 records
                ColumnInfoRecord ciStart = ci;
                ColumnInfoRecord ciMid   = CopyColInfo(ci);
                ColumnInfoRecord ciEnd   = CopyColInfo(ci);
                int lastcolumn           = ci.LastColumn;

                ciStart.LastColumn = (targetColumnIx - 1);

                ciMid.FirstColumn = (targetColumnIx);
                ciMid.LastColumn  = (targetColumnIx);
                SetColumnInfoFields(ciMid, xfIndex, width, level, hidden, collapsed);
                InsertColumn(++k, ciMid);

                ciEnd.FirstColumn = (targetColumnIx + 1);
                ciEnd.LastColumn  = (lastcolumn);
                InsertColumn(++k, ciEnd);
                // no need to attemptMergeColInfoRecords because we
                // know both on each side are different
            }
        }
Ejemplo n.º 31
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();
        }
Ejemplo n.º 32
0
 public static int CompareColInfos(ColumnInfoRecord a, ColumnInfoRecord b)
 {
     return(a.FirstColumn - b.FirstColumn);
 }