Search in sources :

Example 11 with CTCol

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);
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Example 12 with CTCol

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);
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) TreeSet(java.util.TreeSet) CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Example 13 with CTCol

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;
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol) ArrayList(java.util.ArrayList)

Example 14 with CTCol

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;
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Example 15 with CTCol

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));
        }
    }
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Aggregations

CTCol (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)38 Test (org.junit.Test)19 CTCols (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols)18 CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)7 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)5 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 StylesTable (org.apache.poi.xssf.model.StylesTable)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 ColumnHelper (org.apache.poi.xssf.usermodel.helpers.ColumnHelper)1 CTXf (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf)1