List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getColumnHelper
public ColumnHelper getColumnHelper()
From source file:com.vaadin.addon.spreadsheet.GroupingUtil.java
public static void collapseColumn(XSSFSheet sheet, int columnNumber) { CTCols cols = sheet.getCTWorksheet().getColsArray(0); CTCol col = sheet.getColumnHelper().getColumn(columnNumber, false); int colInfoIx = sheet.getColumnHelper().getIndexOfColumn(cols, col); if (colInfoIx == -1) { return;/*from w w w . j av a 2 s .c o m*/ } // Find the start of the group. int groupStartColInfoIx = (Integer) callSheetMethod("findStartOfColumnOutlineGroup", sheet, colInfoIx); /** START */ // Hide all the columns until the end of the group int lastColMax = (Integer) callSheetMethod("setGroupHidden", sheet, new Object[] { groupStartColInfoIx, col.getOutlineLevel(), true }); /** END */ // write collapse field callSheetMethod("setColumn", sheet, new Object[] { lastColMax + 1, 0, null, null, Boolean.TRUE }); }
From source file:com.vaadin.addon.spreadsheet.GroupingUtil.java
public static short expandColumn(XSSFSheet sheet, int columnIndex) { CTCols cols = sheet.getCTWorksheet().getColsArray(0); CTCol col = sheet.getColumnHelper().getColumn(columnIndex, false); int colInfoIx = sheet.getColumnHelper().getIndexOfColumn(cols, col); int idx = (Integer) callSheetMethod("findColInfoIdx", sheet, new Object[] { (int) col.getMax(), colInfoIx }); if (idx == -1) { return -1; }//from w ww. j a v a 2s.c o m // If it is already expanded do nothing. if (!isColumnGroupCollapsed(sheet, idx)) { return -1; } // Find the start/end of the group. int startIdx = (Integer) callSheetMethod("findStartOfColumnOutlineGroup", sheet, idx); int endIdx = (Integer) callSheetMethod("findEndOfColumnOutlineGroup", sheet, idx); // expand: // colapsed bit must be unset // hidden bit gets unset _if_ surrounding groups are expanded you can // determine // this by looking at the hidden bit of the enclosing group. You will // have // to look at the start and the end of the current group to determine // which // is the enclosing group // hidden bit only is altered for this outline level. ie. don't // uncollapse contained groups CTCol[] colArray = cols.getColArray(); @SuppressWarnings("unused") CTCol columnInfo = colArray[endIdx]; short expandedLevel = -1; if (!isColumnGroupHiddenByParent(sheet, idx)) { /** Start */ short outlineLevel = col.getOutlineLevel(); /** end */ boolean nestedGroup = false; for (int i = startIdx; i <= endIdx; i++) { CTCol ci = colArray[i]; if (outlineLevel == ci.getOutlineLevel()) { ci.unsetHidden(); if (nestedGroup) { nestedGroup = false; ci.setCollapsed(true); } expandedLevel = outlineLevel; } else { nestedGroup = true; } } } /** start */ // // Write collapse flag (stored in a single col info record after this // // outline group) // callSheetMethod("setColumn", sheet, // new Object[] { (int) columnInfo.getMax() + 1, null, null, // Boolean.FALSE, Boolean.FALSE }); /** end */ return expandedLevel; }