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); }
public void TestSortColumns() { //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 = (11); Assert.AreEqual(4, cols1.sizeOfColArray()); CT_Col col5 = cols1.AddNewCol(); col5.min = (4); col5.max = (5); Assert.AreEqual(5, cols1.sizeOfColArray()); CT_Col col6 = cols1.AddNewCol(); col6.min = (8); col6.max = (9); col6.hidden = (true); CT_Col col7 = cols1.AddNewCol(); col7.min = (6); col7.max = (8); col7.width = (17.0); CT_Col col8 = cols1.AddNewCol(); col8.min = (25); col8.max = (27); CT_Col col9 = cols1.AddNewCol(); col9.min = (20); col9.max = (30); Assert.AreEqual(9, cols1.sizeOfColArray()); Assert.AreEqual(20u, cols1.GetColArray(8).min); Assert.AreEqual(30u, cols1.GetColArray(8).max); ColumnHelper.SortColumns(cols1); Assert.AreEqual(9, cols1.sizeOfColArray()); Assert.AreEqual(25u, cols1.GetColArray(8).min); Assert.AreEqual(27u, cols1.GetColArray(8).max); }
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); }
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); }
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); }
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); }
public CT_Col GetColumn1Based(long index1, bool splitColumns) { CT_Cols colsArray = this.worksheet.GetColsArray(0); for (int index = 0; index < colsArray.sizeOfColArray(); ++index) { CT_Col colArray = colsArray.GetColArray(index); if ((long)colArray.min <= index1 && (long)colArray.max >= index1) { if (splitColumns) { if ((long)colArray.min < index1) { this.insertCol(colsArray, (long)colArray.min, index1 - 1L, new CT_Col[1] { colArray }); } if ((long)colArray.max > index1) { this.insertCol(colsArray, index1 + 1L, (long)colArray.max, new CT_Col[1] { colArray }); } colArray.min = (uint)index1; colArray.max = (uint)index1; } return(colArray); } } return((CT_Col)null); }
/** * Returns the Column at the given 1 based index. * POI default is 0 based, but the file stores * as 1 based. */ public CT_Col GetColumn1Based(long index1, bool splitColumns) { CT_Cols colsArray = worksheet.GetColsArray(0); for (int i = 0; i < colsArray.sizeOfColArray(); i++) { CT_Col colArray = colsArray.GetColArray(i); if (colArray.min <= index1 && colArray.max >= index1) { if (splitColumns) { if (colArray.min < index1) { insertCol(colsArray, colArray.min, (index1 - 1), new CT_Col[] { colArray }); } if (colArray.max > index1) { insertCol(colsArray, (index1 + 1), colArray.max, new CT_Col[] { colArray }); } colArray.min = (uint)(index1); colArray.max = (uint)(index1); } return(colArray); } } return(null); }
//YK: GetXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public static void SortColumns(CT_Cols newCols) { List <CT_Col> colArray = newCols.GetColArray(); colArray.Sort(new CTColComparator()); newCols.SetColArray(colArray); }
//YK: GetXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public void CleanColumns() { this.newCols = new CT_Cols(); List <CT_Cols> colsArray = worksheet.GetColsArray(); if (null != colsArray) { int i = 0; for (i = 0; i < colsArray.Count; i++) { CT_Cols cols = colsArray[i]; List <CT_Col> colArray = cols.GetColArray(); for (int y = 0; y < colArray.Count; y++) { CT_Col col = colArray[y]; newCols = AddCleanColIntoCols(newCols, col); } } for (int y = i - 1; y >= 0; y--) { worksheet.RemoveCols(y); } } worksheet.AddNewCols(); worksheet.SetColsArray(0, newCols); }
private void assertMinMaxHiddenBestFit(CT_Cols cols, int index, int min, int max, bool hidden, bool bestFit) { CT_Col col = cols.GetColArray(index); Assert.AreEqual(min, col.min); Assert.AreEqual(max, col.max); Assert.AreEqual(hidden, col.hidden); Assert.AreEqual(bestFit, col.bestFit); }
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); }
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); }
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); }
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); }
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); }
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); }