use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method setColDefaultStyle.
public void setColDefaultStyle(long index, int styleId) {
CTCol col = getOrCreateColumn1Based(index + 1, true);
col.setStyle(styleId);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method cleanColumns.
public void cleanColumns() {
TreeSet<CTCol> trackedCols = new TreeSet<CTCol>(CTColComparator.BY_MIN_MAX);
CTCols newCols = CTCols.Factory.newInstance();
CTCols[] colsArray = worksheet.getColsArray();
int i = 0;
for (i = 0; i < colsArray.length; i++) {
CTCols cols = colsArray[i];
CTCol[] colArray = cols.getColArray();
for (CTCol col : colArray) {
addCleanColIntoCols(newCols, col, trackedCols);
}
}
for (int y = i - 1; y >= 0; y--) {
worksheet.removeCols(y);
}
newCols.setColArray(trackedCols.toArray(new CTCol[trackedCols.size()]));
worksheet.addNewCols();
worksheet.setColsArray(0, newCols);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method getOverlappingCols.
private List<CTCol> getOverlappingCols(final CTCol newCol, final TreeSet<CTCol> trackedCols) {
CTCol lower = trackedCols.lower(newCol);
NavigableSet<CTCol> potentiallyOverlapping = lower == null ? trackedCols : trackedCols.tailSet(lower, overlaps(lower, newCol));
List<CTCol> overlapping = new ArrayList<CTCol>();
for (CTCol existing : potentiallyOverlapping) {
if (overlaps(newCol, existing)) {
overlapping.add(existing);
} else {
break;
}
}
return overlapping;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method insertCol.
private CTCol insertCol(CTCols cols, long min, long max, CTCol[] colsWithAttributes, boolean ignoreExistsCheck, CTCol overrideColumn) {
if (ignoreExistsCheck || !columnExists(cols, min, max)) {
CTCol newCol = cols.insertNewCol(0);
newCol.setMin(min);
newCol.setMax(max);
for (CTCol col : colsWithAttributes) {
setColumnAttributes(col, newCol);
}
if (overrideColumn != null)
setColumnAttributes(overrideColumn, newCol);
return newCol;
}
return null;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method addCleanColIntoCols.
private void addCleanColIntoCols(final CTCols cols, final CTCol newCol, final TreeSet<CTCol> trackedCols) {
List<CTCol> overlapping = getOverlappingCols(newCol, trackedCols);
if (overlapping.isEmpty()) {
trackedCols.add(cloneCol(cols, newCol));
return;
}
trackedCols.removeAll(overlapping);
for (CTCol existing : overlapping) {
// We add up to three columns for each existing one: non-overlap
// before, overlap, non-overlap after.
long[] overlap = getOverlap(newCol, existing);
CTCol overlapCol = cloneCol(cols, existing, overlap);
setColumnAttributes(newCol, overlapCol);
trackedCols.add(overlapCol);
CTCol beforeCol = existing.getMin() < newCol.getMin() ? existing : newCol;
long[] before = new long[] { Math.min(existing.getMin(), newCol.getMin()), overlap[0] - 1 };
if (before[0] <= before[1]) {
trackedCols.add(cloneCol(cols, beforeCol, before));
}
CTCol afterCol = existing.getMax() > newCol.getMax() ? existing : newCol;
long[] after = new long[] { overlap[1] + 1, Math.max(existing.getMax(), newCol.getMax()) };
if (after[0] <= after[1]) {
trackedCols.add(cloneCol(cols, afterCol, after));
}
}
}
Aggregations