public void SetColDefaultStyle(long index, int styleId) { CT_Col col = GetOrCreateColumn1Based(index + 1, true); col.style = (uint)styleId; col.styleSpecified = true; }
public void TestColumn() { CT_Worksheet worksheet = new CT_Worksheet(); CT_Cols cols1 = worksheet.AddNewCols(); 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_Cols cols2 = worksheet.AddNewCols(); CT_Col col4 = cols2.AddNewCol(); col4.min = (3); col4.max = (6); // Remember - POI column 0 == OOXML column 1 ColumnHelper helper = new ColumnHelper(worksheet); Assert.IsNotNull(helper.GetColumn(0, false)); Assert.IsNotNull(helper.GetColumn(1, false)); Assert.AreEqual(88.0, helper.GetColumn(0, false).width, 0.0); Assert.AreEqual(0.0, helper.GetColumn(1, false).width, 0.0); Assert.IsTrue(helper.GetColumn(0, false).hidden); Assert.IsFalse(helper.GetColumn(1, false).hidden); Assert.IsNull(helper.GetColumn(99, false)); Assert.IsNotNull(helper.GetColumn(5, false)); }
//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); }
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); }
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); }
public override int Compare(CT_Col col1, CT_Col col2) { long col11min = col1.min; long col2min = col2.min; return(col11min <col2min ? -1 : col11min> col2min ? 1 : BY_MAX.Compare(col1, col2)); }
/** * 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); // Fetching the array is quicker than working on the new style // list, assuming we need to read many of them (which we often do), // and assuming we're not making many changes (which we're not) CT_Col[] cols = colsArray.GetColList().ToArray(); for (int i = 0; i < cols.Length; i++) { CT_Col colArray = cols[i]; long colMin = colArray.min; long colMax = colArray.max; if (colMin <= index1 && colMax >= index1) { if (splitColumns) { if (colMin < index1) { insertCol(colsArray, colMin, (index1 - 1), new CT_Col[] { colArray }); } if (colMax > index1) { insertCol(colsArray, (index1 + 1), colMax, new CT_Col[] { colArray }); } colArray.min = (uint)(index1); colArray.max = (uint)(index1); } return(colArray); } } return(null); }
public override int Compare(CT_Col col1, CT_Col col2) { long col1max = col1.max; long col2max = col2.max; return(col1max <col2max ? -1 : col1max> col2max ? 1 : 0); }
public XMLColumnModel(CT_Col col, int number) { _col = col; _colnumber = number; _interface = new ColumnProperties(this); _col.Width_Attr = 9.140625; }
/** * 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); }
private CT_Col cloneCol(CT_Cols cols, CT_Col col, long[] newRange) { CT_Col cloneCol = CloneCol(cols, col); cloneCol.min = (uint)(newRange[0]); cloneCol.max = (uint)(newRange[1]); return(cloneCol); }
private CT_Col createCol(int min, int max) { CT_Col col = new CT_Col(); col.min = (uint)(min); col.max = (uint)(max); return(col); }
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; }
public CT_Col CloneCol(CT_Cols cols, CT_Col col) { CT_Col toCol = cols.AddNewCol(); toCol.min = col.min; toCol.max = col.max; this.SetColumnAttributes(col, toCol); return(toCol); }
private float GetColumnWidthInPixels(int columnIndex) { XSSFSheet sheet = (XSSFSheet)GetDrawing().GetParent(); CT_Col col = sheet.GetColumnHelper().GetColumn(columnIndex, false); double numChars = col == null || !col.IsSetWidth() ? DEFAULT_COLUMN_WIDTH : col.width; return((float)numChars * XSSFWorkbook.DEFAULT_CHARACTER_WIDTH); }
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); }
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); }
// Returns -1 if no column is found for the given index public int GetColDefaultStyle(long index) { CT_Col col = GetColumn(index, false); if (col != null && col.style != null) { return((int)col.style); } return(-1); }
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 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); }
/** * Return the CT_Col at the given (0 based) column index, * creating it if required. */ internal CT_Col GetOrCreateColumn1Based(long index1, bool splitColumns) { CT_Col col = GetColumn1Based(index1, splitColumns); if (col == null) { col = worksheet.GetColsArray(0).AddNewCol(); col.min = (uint)(index1); col.max = (uint)(index1); } return col; }
internal CT_Col GetOrCreateColumn1Based(long index1, bool splitColumns) { CT_Col ctCol = this.GetColumn1Based(index1, splitColumns); if (ctCol == null) { ctCol = this.worksheet.GetColsArray(0).AddNewCol(); ctCol.min = (uint)index1; ctCol.max = (uint)index1; } return(ctCol); }
public CT_Cols addCleanColIntoCols(CT_Cols cols, CT_Col newCol) { // Performance issue. If we encapsulated management of min/max in this // class then we could keep trackedCols as state, // making this log(N) rather than Nlog(N). We do this for the initial // read above. TreeSet <CT_Col> trackedCols = new TreeSet <CT_Col>(CTColComparator.BY_MIN_MAX); trackedCols.AddAll(cols.GetColList()); addCleanColIntoCols(cols, newCol, trackedCols); cols.SetColArray(trackedCols.ToArray(new CT_Col[0])); return(cols); }
/** * Creates and adds a hidden column and then a best fit column with the given min/max pairs. * Suitable for testing handling of overlap. */ private CT_Cols createHiddenAndBestFitColsWithHelper(int hiddenMin, int hiddenMax, int bestFitMin, int bestFitMax) { CT_Worksheet worksheet = new CT_Worksheet(); ColumnHelper helper = new ColumnHelper(worksheet); CT_Cols cols = worksheet.GetColsArray(0); CT_Col hidden = createCol(hiddenMin, hiddenMax); hidden.hidden = (true); helper.addCleanColIntoCols(cols, hidden); CT_Col bestFit = createCol(bestFitMin, bestFitMax); bestFit.bestFit = (true); helper.addCleanColIntoCols(cols, bestFit); return(cols); }
private CT_Col insertCol(CT_Cols cols, long min, long max, CT_Col[] colsWithAttributes) { if (this.columnExists(cols, min, max)) { return((CT_Col)null); } CT_Col toCol = cols.InsertNewCol(0); toCol.min = (uint)min; toCol.max = (uint)max; foreach (CT_Col colsWithAttribute in colsWithAttributes) { this.SetColumnAttributes(colsWithAttribute, toCol); } return(toCol); }
public CT_Cols AddCleanColIntoCols(CT_Cols cols, CT_Col col) { CT_Cols newCols = new CT_Cols(); foreach (CT_Col c in cols.GetColList()) { CloneCol(newCols, c); } CloneCol(newCols, col); SortColumns(newCols); CT_Col[] colArray = newCols.GetColList().ToArray(); CT_Cols returnCols = new CT_Cols(); SweepCleanColumns(returnCols, colArray, col); colArray = returnCols.GetColList().ToArray(); cols.SetColArray(colArray); return returnCols; }
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); }
/* * 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); }
private CT_Col insertCol(CT_Cols cols, long min, long max, CT_Col[] colsWithAttributes, bool ignoreExistsCheck, CT_Col overrideColumn) { if (ignoreExistsCheck || !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); } if (overrideColumn != null) SetColumnAttributes(overrideColumn, newCol); return newCol; } return null; }