Exemple #1
0
        public void TestAddCleanColIntoColsOverlapsCompletelyNested()
        {
            CT_Cols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);

            Assert.AreEqual(3, cols.sizeOfColArray());
            assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
            assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
            assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
        }
Exemple #2
0
        public void TestAddCleanColIntoColsOverlapsOverhangingBothSides()
        {
            CT_Cols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3);

            Assert.AreEqual(3, cols.sizeOfColArray());
            assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
            assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
            assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
        }
Exemple #3
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);
 }
Exemple #4
0
 private bool columnExists(CT_Cols cols, long min, long max)
 {
     for (int i = 0; i < cols.sizeOfColArray(); i++)
     {
         if (cols.GetColArray(i).min == min && cols.GetColArray(i).max == max)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
 private bool columnExists1Based(CT_Cols cols, long index1)
 {
     for (int i = 0; i < cols.sizeOfColArray(); i++)
     {
         if (cols.GetColArray(i).min == index1)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #6
0
 public int GetIndexOfColumn(CT_Cols cols, CT_Col col)
 {
     for (int index = 0; index < cols.sizeOfColArray(); ++index)
     {
         if ((int)cols.GetColArray(index).min == (int)col.min && (int)cols.GetColArray(index).max == (int)col.max)
         {
             return(index);
         }
     }
     return(-1);
 }
Exemple #7
0
 private bool columnExists(CT_Cols cols, long min, long max)
 {
     for (int index = 0; index < cols.sizeOfColArray(); ++index)
     {
         if ((long)cols.GetColArray(index).min == min && (long)cols.GetColArray(index).max == max)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #8
0
 private bool columnExists1Based(CT_Cols cols, long index1)
 {
     for (int index = 0; index < cols.sizeOfColArray(); ++index)
     {
         if ((long)cols.GetColArray(index).min == index1)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #9
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());

            // No overlap
            helper.addCleanColIntoCols(cols1, createCol(4, 5));
            Assert.AreEqual(5, cols1.sizeOfColArray());

            // Overlaps with 8 - 9 (overlap and after replacements required)
            CT_Col col6 = createCol(8, 11);

            col6.hidden = (true);
            helper.AddCleanColIntoCols(cols1, col6);
            Assert.AreEqual(6, cols1.sizeOfColArray());

            // Overlaps with 8 - 9 (before and overlap replacements required)
            CT_Col col7 = createCol(6, 8);

            col7.width = (17.0);
            helper.AddCleanColIntoCols(cols1, col7);
            Assert.AreEqual(8, cols1.sizeOfColArray());

            // Overlaps with 13 - 16750 (before, overlap and after replacements required)
            helper.addCleanColIntoCols(cols1, createCol(20, 30));
            Assert.AreEqual(10, cols1.sizeOfColArray());

            // Overlaps with 20 - 30 (before, overlap and after replacements required)
            helper.addCleanColIntoCols(cols1, createCol(25, 27));

            // TODO - assert something interesting
            Assert.AreEqual(12, cols1.col.Count);
            Assert.AreEqual(1u, cols1.GetColArray(0).min);
            Assert.AreEqual(16750u, cols1.GetColArray(11).max);
        }
Exemple #10
0
        public void TestMergingOverlappingCols_OVERLAPS_2_MINOR()
        {
            XSSFWorkbook wb    = new XSSFWorkbook();
            XSSFSheet    sheet = (XSSFSheet)wb.CreateSheet("test");

            CT_Cols cols = sheet.GetCTWorksheet().GetColsArray(0);
            CT_Col  col  = cols.AddNewCol();

            col.min         = (2 + 1);
            col.max         = (4 + 1);
            col.width       = (20);
            col.customWidth = (true);

            sheet.GroupColumn((short)1, (short)3);

            cols = sheet.GetCTWorksheet().GetColsArray(0);
            //logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_MINOR/cols:" + cols);

            Assert.AreEqual(1, cols.GetColArray(0).outlineLevel);
            Assert.AreEqual(2, cols.GetColArray(0).min); // 1 based
            Assert.AreEqual(2, cols.GetColArray(0).max); // 1 based
            Assert.AreEqual(false, cols.GetColArray(0).customWidth);

            Assert.AreEqual(1, cols.GetColArray(1).outlineLevel);
            Assert.AreEqual(3, cols.GetColArray(1).min); // 1 based
            Assert.AreEqual(4, cols.GetColArray(1).max); // 1 based
            Assert.AreEqual(true, cols.GetColArray(1).customWidth);

            Assert.AreEqual(0, cols.GetColArray(2).outlineLevel);
            Assert.AreEqual(5, cols.GetColArray(2).min); // 1 based
            Assert.AreEqual(5, cols.GetColArray(2).max); // 1 based
            Assert.AreEqual(true, cols.GetColArray(2).customWidth);

            Assert.AreEqual(3, cols.sizeOfColArray());

            wb    = XSSFTestDataSamples.WriteOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_2_MINOR");
            sheet = (XSSFSheet)wb.GetSheet("test");

            for (int i = 2; i <= 4; i++)
            {
                Assert.AreEqual(20 * 256, sheet.GetColumnWidth(i), "Unexpected width of column " + i);
            }
            Assert.AreEqual(sheet.DefaultColumnWidth * 256, sheet.GetColumnWidth(1), "Unexpected width of column " + 1);
        }
Exemple #11
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);
        }
Exemple #12
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);
        }
Exemple #13
0
        public CT_Cols AddCleanColIntoCols(CT_Cols cols, CT_Col col)
        {
            bool flag = false;

            for (int index = 0; index < cols.sizeOfColArray(); ++index)
            {
                CT_Col colArray = cols.GetColArray(index);
                long[] range1   = new long[2] {
                    (long)colArray.min, (long)colArray.max
                };
                long[] range2 = new long[2] {
                    (long)col.min, (long)col.max
                };
                long[] overlappingRange = NumericRanges.GetOverlappingRange(range1, range2);
                int    overlappingType  = NumericRanges.GetOverlappingType(range1, range2);
                if (overlappingType == 0)
                {
                    colArray.max = (uint)((ulong)overlappingRange[0] - 1UL);
                    this.insertCol(cols, overlappingRange[0], overlappingRange[1], new CT_Col[2]
                    {
                        colArray,
                        col
                    });
                    int num = index + 1;
                    this.insertCol(cols, overlappingRange[1] + 1L, (long)col.max, new CT_Col[1]
                    {
                        col
                    });
                    index = num + 1;
                }
                else if (overlappingType == 1)
                {
                    colArray.min = (uint)((ulong)overlappingRange[1] + 1UL);
                    this.insertCol(cols, overlappingRange[0], overlappingRange[1], new CT_Col[2]
                    {
                        colArray,
                        col
                    });
                    int num = index + 1;
                    this.insertCol(cols, (long)col.min, overlappingRange[0] - 1L, new CT_Col[1]
                    {
                        col
                    });
                    index = num + 1;
                }
                else if (overlappingType == 3)
                {
                    this.SetColumnAttributes(col, colArray);
                    if ((int)col.min != (int)colArray.min)
                    {
                        this.insertCol(cols, (long)col.min, (long)(colArray.min - 1U), new CT_Col[1]
                        {
                            col
                        });
                        ++index;
                    }
                    if ((int)col.max != (int)colArray.max)
                    {
                        this.insertCol(cols, (long)(colArray.max + 1U), (long)col.max, new CT_Col[1]
                        {
                            col
                        });
                        ++index;
                    }
                }
                else if (overlappingType == 2)
                {
                    if ((int)col.min != (int)colArray.min)
                    {
                        this.insertCol(cols, (long)colArray.min, (long)(col.min - 1U), new CT_Col[1]
                        {
                            colArray
                        });
                        ++index;
                    }
                    if ((int)col.max != (int)colArray.max)
                    {
                        this.insertCol(cols, (long)(col.max + 1U), (long)colArray.max, new CT_Col[1]
                        {
                            colArray
                        });
                        ++index;
                    }
                    colArray.min = (uint)overlappingRange[0];
                    colArray.max = (uint)overlappingRange[1];
                    this.SetColumnAttributes(col, colArray);
                }
                if (overlappingType != -1)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                this.CloneCol(cols, col);
            }
            ColumnHelper.SortColumns(cols);
            return(cols);
        }