Exemplo n.º 1
0
        public static CT_Col Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Col ctObj = new CT_Col();

            ctObj.min   = XmlHelper.ReadUInt(node.Attributes["min"]);
            ctObj.max   = XmlHelper.ReadUInt(node.Attributes["max"]);
            ctObj.width = XmlHelper.ReadDouble(node.Attributes["width"]);
            if (node.Attributes["style"] != null)
            {
                ctObj.style = XmlHelper.ReadUInt(node.Attributes["style"]);
            }
            else
            {
                ctObj.style = null;
            }
            ctObj.hidden       = XmlHelper.ReadBool(node.Attributes["hidden"]);
            ctObj.bestFit      = XmlHelper.ReadBool(node.Attributes["bestFit"]);
            ctObj.outlineLevel = XmlHelper.ReadByte(node.Attributes["outlineLevel"]);
            ctObj.customWidth  = XmlHelper.ReadBool(node.Attributes["customWidth"]);
            ctObj.phonetic     = XmlHelper.ReadBool(node.Attributes["phonetic"]);
            ctObj.collapsed    = XmlHelper.ReadBool(node.Attributes["collapsed"]);
            return(ctObj);
        }
Exemplo n.º 2
0
 public void TestArraysSort()
 {
     CTColComparator comparator = new CTColComparator();
     CT_Col o1 = new CT_Col();
     o1.min = 1;
     o1.max = 10;
     CT_Col o2 = new CT_Col();
     o2.min = 11;
     o2.max = 12;
     Assert.AreEqual(-1, comparator.Compare(o1, o2));
     CT_Col o3 = new CT_Col();
     o3.min = 5;
     o3.max = 80;
     CT_Col o4 = new CT_Col();
     o4.min = 5;
     o4.max = 8;
     Assert.AreEqual(1, comparator.Compare(o3, o4));
     CT_Col[] cols = new CT_Col[4];
     cols[0] = o1;
     cols[1] = o2;
     cols[2] = o3;
     cols[3] = o4;
     Assert.AreEqual((uint)80, cols[2].max);
     Assert.AreEqual((uint)8, cols[3].max);
     Array.Sort(cols, comparator);
     Assert.AreEqual((uint)12, cols[3].max);
     Assert.AreEqual((uint)8, cols[1].max);
     Assert.AreEqual((uint)80, cols[2].max);
 }
Exemplo n.º 3
0
        public CT_Col AddNewCol()
        {
            CT_Col newCol = new CT_Col();

            this.colField.Add(newCol);
            return(newCol);
        }
Exemplo n.º 4
0
        public CT_Col InsertNewCol(int index)
        {
            CT_Col newCol = new CT_Col();

            this.colField.Insert(index, newCol);
            return(newCol);
        }
Exemplo n.º 5
0
        public void TestAddCleanColIntoCols()
        {
            CT_Worksheet worksheet = new CT_Worksheet();
            ColumnHelper helper = new ColumnHelper(worksheet);

            CT_Cols cols1 = new CT_Cols();
            CT_Col col1 = cols1.AddNewCol();
            col1.min = (1);
            col1.max = (1);
            col1.width = (88);
            col1.hidden = (true);
            CT_Col col2 = cols1.AddNewCol();
            col2.min = (2);
            col2.max = (3);
            CT_Col col3 = cols1.AddNewCol();
            col3.min = (13);
            col3.max = (16750);
            Assert.AreEqual(3, cols1.sizeOfColArray());
            CT_Col col4 = cols1.AddNewCol();
            col4.min = (8);
            col4.max = (9);
            Assert.AreEqual(4, cols1.sizeOfColArray());

            CT_Col col5 = new CT_Col();
            col5.min = (4);
            col5.max = (5);
            helper.AddCleanColIntoCols(cols1, col5);
            Assert.AreEqual(5, cols1.sizeOfColArray());

            CT_Col col6 = new CT_Col();
            col6.min = (8);
            col6.max = (11);
            col6.hidden = (true);
            helper.AddCleanColIntoCols(cols1, col6);
            Assert.AreEqual(6, cols1.sizeOfColArray());

            CT_Col col7 = new CT_Col();
            col7.min = (6);
            col7.max = (8);
            col7.width = (17.0);
            helper.AddCleanColIntoCols(cols1, col7);
            Assert.AreEqual(8, cols1.sizeOfColArray());

            CT_Col col8 = new CT_Col();
            col8.min = (20);
            col8.max = (30);
            helper.AddCleanColIntoCols(cols1, col8);
            Assert.AreEqual(10, cols1.sizeOfColArray());

            CT_Col col9 = new CT_Col();
            col9.min = (25);
            col9.max = (27);
            helper.AddCleanColIntoCols(cols1, col9);

            // TODO - assert something interesting
            Assert.AreEqual(12, cols1.col.Count);
            Assert.AreEqual(1u, cols1.GetColArray(0).min);
            Assert.AreEqual(16750u, cols1.GetColArray(11).max);
        }
Exemplo n.º 6
0
 public CT_Col CloneCol(CT_Cols cols, CT_Col col)
 {
     CT_Col newCol = cols.AddNewCol();
     newCol.min = (uint)(col.min);
     newCol.max = (uint)(col.max);
     SetColumnAttributes(col, newCol);
     return newCol;
 }
Exemplo n.º 7
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is CT_Col))
            {
                return(false);
            }
            CT_Col col = obj as CT_Col;

            return(col.min == this.min && col.max == this.max);
        }
Exemplo n.º 8
0
 public void TestCompare()
 {
     CTColComparator comparator = new CTColComparator();
     CT_Col o1 = new CT_Col();
     o1.min = 1;
     o1.max = 10;
     CT_Col o2 = new CT_Col();
     o2.min = 11;
     o2.max = 12;
     Assert.AreEqual(-1, comparator.Compare(o1, o2));
     CT_Col o3 = new CT_Col();
     o3.min = 5;
     o3.max = 8;
     CT_Col o4 = new CT_Col();
     o4.min = 5;
     o4.max = 80;
     Assert.AreEqual(-1, comparator.Compare(o3, o4));
 }
Exemplo n.º 9
0
        public static CT_Cols Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Cols ctObj = new CT_Cols();

            ctObj.col = new List <CT_Col>();
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "col")
                {
                    ctObj.col.Add(CT_Col.Parse(childNode, namespaceManager));
                }
            }
            return(ctObj);
        }
Exemplo n.º 10
0
        public CT_Col Copy()
        {
            CT_Col col = new CT_Col();

            col.bestFitField            = this.bestFitField;
            col.collapsedField          = this.collapsedField;
            col.collapsedSpecifiedField = this.collapsedSpecifiedField;
            col.customWidthField        = this.customWidthField;
            col.hiddenField             = this.hiddenField;
            col.maxField            = this.maxField;
            col.minField            = this.minField;
            col.outlineLevelField   = this.outlineLevelField;
            col.phoneticField       = this.phoneticField;
            col.styleField          = this.styleField;
            col.widthField          = this.widthField;
            col.widthSpecifiedField = this.widthSpecifiedField;

            return(col);
        }
Exemplo n.º 11
0
 public static CT_Col Parse(XmlNode node, XmlNamespaceManager namespaceManager)
 {
     if (node == null)
         return null;
     CT_Col ctObj = new CT_Col();
     ctObj.min = XmlHelper.ReadUInt(node.Attributes["min"]);
     ctObj.max = XmlHelper.ReadUInt(node.Attributes["max"]);
     ctObj.width = XmlHelper.ReadDouble(node.Attributes["width"]);
     ctObj.style = XmlHelper.ReadUInt(node.Attributes["style"]);
     ctObj.hidden = XmlHelper.ReadBool(node.Attributes["hidden"]);
     ctObj.bestFit = XmlHelper.ReadBool(node.Attributes["bestFit"]);
     ctObj.customWidth = XmlHelper.ReadBool(node.Attributes["customWidth"]);
     ctObj.phonetic = XmlHelper.ReadBool(node.Attributes["phonetic"]);
     ctObj.collapsed = XmlHelper.ReadBool(node.Attributes["collapsed"]);
     return ctObj;
 }
Exemplo n.º 12
0
 private bool ContainsColumn(CT_Col col, int columnIndex)
 {
     return col.min <= columnIndex && columnIndex <= col.max;
 }
Exemplo n.º 13
0
 private bool IsAdjacentBefore(CT_Col col, CT_Col other_col)
 {
     return (col.max == (other_col.min - 1));
 }
Exemplo n.º 14
0
 private void UnsetCollapsed(bool collapsed, CT_Col ci)
 {
     if (collapsed)
     {
         ci.collapsed = (collapsed);
     }
     else
     {
         ci.UnsetCollapsed();
     }
 }
Exemplo n.º 15
0
        private void SetColumn(int targetColumnIx, short? xfIndex, int? style,
                int? level, Boolean? hidden, Boolean? collapsed)
        {
            CT_Cols cols = worksheet.GetColsArray(0);
            CT_Col ci = null;
            int k = 0;
            for (k = 0; k < cols.sizeOfColArray(); k++)
            {
                CT_Col tci = cols.GetColArray(k);
                if (tci.min >= targetColumnIx
                        && tci.max <= targetColumnIx)
                {
                    ci = tci;
                    break;
                }
                if (tci.min > targetColumnIx)
                {
                    // call column infos after k are for later columns
                    break; // exit now so k will be the correct insert pos
                }
            }

            if (ci == null)
            {
                // okay so there ISN'T a column info record that covers this column
                // so lets create one!
                CT_Col nci = new CT_Col();
                nci.min = (uint)targetColumnIx;
                nci.max = (uint)targetColumnIx;
                UnsetCollapsed((bool)collapsed, nci);
                this.columnHelper.AddCleanColIntoCols(cols, nci);
                return;
            }

            bool styleChanged = style != null
            && ci.style != style;
            bool levelChanged = level != null
            && ci.outlineLevel != level;
            bool hiddenChanged = hidden != null
            && ci.hidden != hidden;
            bool collapsedChanged = collapsed != null
            && ci.collapsed != collapsed;
            bool columnChanged = levelChanged || hiddenChanged
            || collapsedChanged || styleChanged;
            if (!columnChanged)
            {
                // do nothing...nothing Changed.
                return;
            }

            if (ci.min == targetColumnIx && ci.max == targetColumnIx)
            {
                // ColumnInfo ci for a single column, the target column
                UnsetCollapsed((bool)collapsed, ci);
                return;
            }

            if (ci.min == targetColumnIx || ci.max == 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.min == targetColumnIx)
                {
                    ci.min = (uint)(targetColumnIx + 1);
                }
                else
                {
                    ci.max = (uint)(targetColumnIx - 1);
                    k++; // adjust insert pos to insert after
                }
                CT_Col nci = columnHelper.CloneCol(cols, ci);
                nci.min = (uint)(targetColumnIx);
                UnsetCollapsed((bool)collapsed, nci);
                this.columnHelper.AddCleanColIntoCols(cols, nci);

            }
            else
            {
                // split to 3 records
                CT_Col ciStart = ci;
                CT_Col ciMid = columnHelper.CloneCol(cols, ci);
                CT_Col ciEnd = columnHelper.CloneCol(cols, ci);
                int lastcolumn = (int)ci.max;

                ciStart.max = (uint)(targetColumnIx - 1);

                ciMid.min = (uint)(targetColumnIx);
                ciMid.max = (uint)(targetColumnIx);
                UnsetCollapsed((bool)collapsed, ciMid);
                this.columnHelper.AddCleanColIntoCols(cols, ciMid);

                ciEnd.min = (uint)(targetColumnIx + 1);
                ciEnd.max = (uint)(lastcolumn);
                this.columnHelper.AddCleanColIntoCols(cols, ciEnd);
            }
        }
Exemplo n.º 16
0
 private void GroupColumn1Based(int fromColumn, int toColumn)
 {
     CT_Cols ctCols = worksheet.GetColsArray(0);
     CT_Col ctCol = new CT_Col();
     ctCol.min = (uint)fromColumn;
     ctCol.max = (uint)toColumn;
     this.columnHelper.AddCleanColIntoCols(ctCols, ctCol);
     for (int index = fromColumn; index <= toColumn; index++)
     {
         CT_Col col = columnHelper.GetColumn1Based(index, false);
         //col must exist
         short outlineLevel = col.outlineLevel;
         col.outlineLevel = (byte)(outlineLevel + 1);
         index = (int)col.max;
     }
     worksheet.SetColsArray(0, ctCols);
     SetSheetFormatPrOutlineLevelCol();
 }
Exemplo n.º 17
0
 public CT_Col AddNewCol()
 {
     CT_Col newCol = new CT_Col();
     this.colField.Add(newCol);
     return newCol;
 }
Exemplo n.º 18
0
 public void SetColArray(CT_Col[] colArray)
 {
     this.colField = new List<CT_Col>(colArray);
 }
Exemplo n.º 19
0
        private void GroupColumn1Based(int fromColumn, int toColumn)
        {
            CT_Cols ctCols = worksheet.GetColsArray(0);
            CT_Col ctCol = new CT_Col();

            // copy attributes, as they might be removed by merging with the new column
            // TODO: check if this fix is really necessary or if the sweeping algorithm
            // in addCleanColIntoCols needs to be adapted ...
            CT_Col fixCol_before = this.columnHelper.GetColumn1Based(toColumn, false);
            if (fixCol_before != null)
            {
                fixCol_before = (CT_Col)fixCol_before.Copy();
            }

            ctCol.min = (uint)fromColumn;
            ctCol.max = (uint)toColumn;
            this.columnHelper.AddCleanColIntoCols(ctCols, ctCol);

            CT_Col fixCol_after = this.columnHelper.GetColumn1Based(toColumn, false);
            if (fixCol_before != null && fixCol_after != null)
            {
                this.columnHelper.SetColumnAttributes(fixCol_before, fixCol_after);
            }

            for (int index = fromColumn; index <= toColumn; index++)
            {
                CT_Col col = columnHelper.GetColumn1Based(index, false);
                //col must exist
                short outlineLevel = col.outlineLevel;
                col.outlineLevel = (byte)(outlineLevel + 1);
                index = (int)col.max;
            }
            worksheet.SetColsArray(0, ctCols);
            SetSheetFormatPrOutlineLevelCol();
        }
Exemplo n.º 20
0
        public void TestCloneCol()
        {
            CT_Worksheet worksheet = new CT_Worksheet();
            ColumnHelper helper = new ColumnHelper(worksheet);

            CT_Cols cols = new CT_Cols();
            CT_Col col = new CT_Col();
            col.min = (2);
            col.max = (8);
            col.hidden = (true);
            col.width = (13.4);
            CT_Col newCol = helper.CloneCol(cols, col);
            Assert.AreEqual(2u, newCol.min);
            Assert.AreEqual(8u, newCol.max);
            Assert.IsTrue(newCol.hidden);
            Assert.AreEqual(13.4, newCol.width, 0.0);
        }
Exemplo n.º 21
0
 /*
  * Insert a new CT_Col at position 0 into cols, Setting min=min, max=max and
  * copying all the colsWithAttributes array cols attributes into newCol
  */
 private CT_Col insertCol(CT_Cols cols, long min, long max,
     CT_Col[] colsWithAttributes)
 {
     if (!columnExists(cols, min, max))
     {
         CT_Col newCol = cols.InsertNewCol(0);
         newCol.min = (uint)(min);
         newCol.max = (uint)(max);
         foreach (CT_Col col in colsWithAttributes)
         {
             SetColumnAttributes(col, newCol);
         }
         return newCol;
     }
     return null;
 }
Exemplo n.º 22
0
 public CT_Cols AddCleanColIntoCols(CT_Cols cols, CT_Col col)
 {
     bool colOverlaps = false;
     for (int i = 0; i < cols.sizeOfColArray(); i++)
     {
         CT_Col ithCol = cols.GetColArray(i);
         long[] range1 = { ithCol.min, ithCol.max };
         long[] range2 = { col.min, col.max };
         long[] overlappingRange = NumericRanges.GetOverlappingRange(range1,
                 range2);
         int overlappingType = NumericRanges.GetOverlappingType(range1,
                 range2);
         // different behavior required for each of the 4 different
         // overlapping types
         if (overlappingType == NumericRanges.OVERLAPS_1_MINOR)
         {
             ithCol.max = (uint)(overlappingRange[0] - 1);
             CT_Col rangeCol = insertCol(cols, overlappingRange[0],
                     overlappingRange[1], new CT_Col[] { ithCol, col });
             i++;
             CT_Col newCol = insertCol(cols, (overlappingRange[1] + 1), col
                     .max, new CT_Col[] { col });
             i++;
         }
         else if (overlappingType == NumericRanges.OVERLAPS_2_MINOR)
         {
             ithCol.min = (uint)(overlappingRange[1] + 1);
             CT_Col rangeCol = insertCol(cols, overlappingRange[0],
                     overlappingRange[1], new CT_Col[] { ithCol, col });
             i++;
             CT_Col newCol = insertCol(cols, col.min,
                     (overlappingRange[0] - 1), new CT_Col[] { col });
             i++;
         }
         else if (overlappingType == NumericRanges.OVERLAPS_2_WRAPS)
         {
             SetColumnAttributes(col, ithCol);
             if (col.min != ithCol.min)
             {
                 CT_Col newColBefore = insertCol(cols, col.min, (ithCol
                         .min - 1), new CT_Col[] { col });
                 i++;
             }
             if (col.max != ithCol.max)
             {
                 CT_Col newColAfter = insertCol(cols, (ithCol.max + 1),
                         col.max, new CT_Col[] { col });
                 i++;
             }
         }
         else if (overlappingType == NumericRanges.OVERLAPS_1_WRAPS)
         {
             if (col.min != ithCol.min)
             {
                 CT_Col newColBefore = insertCol(cols, ithCol.min, (col
                         .min - 1), new CT_Col[] { ithCol });
                 i++;
             }
             if (col.max != ithCol.max)
             {
                 CT_Col newColAfter = insertCol(cols, (col.max + 1),
                         ithCol.max, new CT_Col[] { ithCol });
                 i++;
             }
             ithCol.min = (uint)(overlappingRange[0]);
             ithCol.max = (uint)(overlappingRange[1]);
             SetColumnAttributes(col, ithCol);
         }
         if (overlappingType != NumericRanges.NO_OVERLAPS)
         {
             colOverlaps = true;
         }
     }
     if (!colOverlaps)
     {
         CT_Col newCol = CloneCol(cols, col);
     }
     SortColumns(cols);
     return cols;
 }
Exemplo n.º 23
0
 public CT_Col InsertNewCol(int index)
 {
     CT_Col newCol = new CT_Col();
     this.colField.Insert(index, newCol);
     return newCol;
 }
Exemplo n.º 24
0
        public void SetColumnAttributes(CT_Col fromCol, CT_Col toCol)
        {

            if (fromCol.IsSetBestFit())
            {
                toCol.bestFit = (fromCol.bestFit);
            }
            if (fromCol.IsSetCustomWidth())
            {
                toCol.customWidth = (fromCol.customWidth);
            }
            if (fromCol.IsSetHidden()) 
            {
                toCol.hidden = (fromCol.hidden);
            }
            if (fromCol.IsSetStyle())
            {
                toCol.style = (fromCol.style);
                toCol.styleSpecified = true;
            }
            if (fromCol.IsSetWidth())
            {
                toCol.width = (fromCol.width);
            }
            if (fromCol.IsSetCollapsed())
            {
                toCol.collapsed = (fromCol.collapsed);
            }
            if (fromCol.IsSetPhonetic())
            {
                toCol.phonetic = (fromCol.phonetic);
            }
            if (fromCol.IsSetOutlineLevel())
            {
                toCol.outlineLevel = (fromCol.outlineLevel);
            }
            if (fromCol.IsSetCollapsed())
            {
                toCol.collapsed = fromCol.collapsed;
            }
        }
Exemplo n.º 25
0
 public void TestSetColumnAttributes()
 {
     CT_Col col = new CT_Col();
     col.width = (12);
     col.hidden = (true);
     CT_Col newCol = new CT_Col();
     Assert.AreEqual(0.0, newCol.width, 0.0);
     Assert.IsFalse(newCol.hidden);
     ColumnHelper helper = new ColumnHelper(new CT_Worksheet());
     helper.SetColumnAttributes(col, newCol);
     Assert.AreEqual(12.0, newCol.width, 0.0);
     Assert.IsTrue(newCol.hidden);
 }
Exemplo n.º 26
0
 public int GetIndexOfColumn(CT_Cols cols, CT_Col col)
 {
     for (int i = 0; i < cols.sizeOfColArray(); i++)
     {
         if (cols.GetColArray(i).min == col.min && cols.GetColArray(i).max == col.max)
         {
             return i;
         }
     }
     return -1;
 }
Exemplo n.º 27
0
 public CT_Col Copy()
 {
     CT_Col col = new CT_Col();
     col.bestFitField = this.bestFitField;
     col.collapsedField = this.collapsedField;
     col.collapsedSpecifiedField = this.collapsedSpecifiedField;
     col.customWidthField = this.customWidthField;
     col.hiddenField = this.hiddenField;
     col.maxField = this.maxField;
     col.minField = this.minField;
     col.outlineLevelField = this.outlineLevelField;
     col.phoneticField = this.phoneticField;
     col.styleField = this.styleField;
     col.widthField = this.widthField;
     col.widthSpecifiedField = this.widthSpecifiedField;
     
     return col;
 }