use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestXSSFSheet method setColumnGroupCollapsed.
/**
* TODO - while this is internally consistent, I'm not
* completely clear in all cases what it's supposed to
* be doing... Someone who understands the goals a little
* better should really review this!
*/
@Test
public void setColumnGroupCollapsed() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet1 = wb1.createSheet();
CTCols cols = sheet1.getCTWorksheet().getColsArray(0);
assertEquals(0, cols.sizeOfColArray());
sheet1.groupColumn(4, 7);
assertEquals(1, cols.sizeOfColArray());
// false, true
checkColumnGroup(cols.getColArray(0), 4, 7);
sheet1.groupColumn(9, 12);
assertEquals(2, cols.sizeOfColArray());
// false, true
checkColumnGroup(cols.getColArray(0), 4, 7);
// false, true
checkColumnGroup(cols.getColArray(1), 9, 12);
sheet1.groupColumn(10, 11);
assertEquals(4, cols.sizeOfColArray());
// false, true
checkColumnGroup(cols.getColArray(0), 4, 7);
// false, true
checkColumnGroup(cols.getColArray(1), 9, 9);
// false, true
checkColumnGroup(cols.getColArray(2), 10, 11);
// false, true
checkColumnGroup(cols.getColArray(3), 12, 12);
// collapse columns - 1
sheet1.setColumnGroupCollapsed(5, true);
// FIXME: we grew a column?
assertEquals(5, cols.sizeOfColArray());
// true, true
checkColumnGroupIsCollapsed(cols.getColArray(0), 4, 7);
// false, true
checkColumnGroup(cols.getColArray(1), 8, 8);
// false, true
checkColumnGroup(cols.getColArray(2), 9, 9);
// false, true
checkColumnGroup(cols.getColArray(3), 10, 11);
// false, true
checkColumnGroup(cols.getColArray(4), 12, 12);
// expand columns - 1
sheet1.setColumnGroupCollapsed(5, false);
assertEquals(5, cols.sizeOfColArray());
// false, true
checkColumnGroupIsExpanded(cols.getColArray(0), 4, 7);
checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
// false, true
checkColumnGroup(cols.getColArray(2), 9, 9);
// false, true
checkColumnGroup(cols.getColArray(3), 10, 11);
// false, true
checkColumnGroup(cols.getColArray(4), 12, 12);
//collapse - 2
sheet1.setColumnGroupCollapsed(9, true);
// it grew again?
assertEquals(6, cols.sizeOfColArray());
// false, true
checkColumnGroup(cols.getColArray(0), 4, 7);
checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
// true, true
checkColumnGroupIsCollapsed(cols.getColArray(2), 9, 9);
// true, true
checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11);
// true, true
checkColumnGroupIsCollapsed(cols.getColArray(4), 12, 12);
// why was this column group added?
// false, true
checkColumnGroup(cols.getColArray(5), 13, 13);
//expand - 2
sheet1.setColumnGroupCollapsed(9, false);
assertEquals(6, cols.sizeOfColArray());
//outline level 2: the line under ==> collapsed==True
assertEquals(2, cols.getColArray(3).getOutlineLevel());
assertTrue(cols.getColArray(4).isSetCollapsed());
checkColumnGroup(cols.getColArray(0), 4, 7);
checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
// false, true
checkColumnGroup(cols.getColArray(2), 9, 9);
// true, true
checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11);
// false, true
checkColumnGroup(cols.getColArray(4), 12, 12);
checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
//DOCUMENTARE MEGLIO IL DISCORSO DEL LIVELLO
//collapse - 3
sheet1.setColumnGroupCollapsed(10, true);
assertEquals(6, cols.sizeOfColArray());
checkColumnGroup(cols.getColArray(0), 4, 7);
checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
// false, true
checkColumnGroup(cols.getColArray(2), 9, 9);
// true, true
checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11);
// false, true
checkColumnGroup(cols.getColArray(4), 12, 12);
checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
//expand - 3
sheet1.setColumnGroupCollapsed(10, false);
assertEquals(6, cols.sizeOfColArray());
assertFalse(cols.getColArray(0).getHidden());
assertFalse(cols.getColArray(5).getHidden());
assertFalse(cols.getColArray(4).isSetCollapsed());
// write out and give back
// Save and re-load
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sheet1 = wb2.getSheetAt(0);
// FIXME: forgot to reassign!
//cols = sheet1.getCTWorksheet().getColsArray(0);
assertEquals(6, cols.sizeOfColArray());
// false, true
checkColumnGroup(cols.getColArray(0), 4, 7);
checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
// false, true
checkColumnGroup(cols.getColArray(2), 9, 9);
// false, true
checkColumnGroup(cols.getColArray(3), 10, 11);
checkColumnGroup(cols.getColArray(4), 12, 12, false, false);
checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
wb2.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class ColumnHelper method cloneCol.
public CTCol cloneCol(CTCols cols, CTCol col) {
CTCol newCol = cols.addNewCol();
newCol.setMin(col.getMin());
newCol.setMax(col.getMax());
setColumnAttributes(col, newCol);
return newCol;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols 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.CTCols 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.CTCols 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