Package org.openxmlformats.schemas.spreadsheetml.x2006.main

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols


      }
      return idx;
    }

    private int findEndOfColumnOutlineGroup(int colInfoIndex) {
      CTCols cols = worksheet.getColsArray(0);
      // Find the end of the group.
      CTCol columnInfo = cols.getColArray(colInfoIndex);
      int level = columnInfo.getOutlineLevel();
      int idx = colInfoIndex;
      while (idx < cols.sizeOfColArray() - 1) {
        CTCol nextColumnInfo = cols.getColArray(idx + 1);
        if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
          break;
        }
        if (nextColumnInfo.getOutlineLevel() < level) {
          break;
View Full Code Here


      }
      return idx;
    }

    private void expandColumn(int columnIndex) {
      CTCols cols = worksheet.getColsArray(0);
      CTCol col = columnHelper.getColumn(columnIndex, false);
      int colInfoIx = columnHelper.getIndexOfColumn(cols, col);

      int idx = findColInfoIdx((int) col.getMax(), colInfoIx);
      if (idx == -1) {
        return;
      }

      // If it is already expanded do nothing.
      if (!isColumnGroupCollapsed(idx)) {
        return;
      }

      // Find the start/end of the group.
      int startIdx = findStartOfColumnOutlineGroup(idx);
      int endIdx = findEndOfColumnOutlineGroup(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 columnInfo = cols.getColArray(endIdx);
      if (!isColumnGroupHiddenByParent(idx)) {
        int outlineLevel = columnInfo.getOutlineLevel();
        boolean nestedGroup = false;
        for (int i = startIdx; i <= endIdx; i++) {
          CTCol ci = cols.getColArray(i);
          if (outlineLevel == ci.getOutlineLevel()) {
            ci.unsetHidden();
            if (nestedGroup) {
              nestedGroup = false;
              ci.setCollapsed(true);
View Full Code Here

      setColumn((int) columnInfo.getMax() + 1, null, null, null,
          Boolean.FALSE, Boolean.FALSE);
    }

    private boolean isColumnGroupHiddenByParent(int idx) {
      CTCols cols = worksheet.getColsArray(0);
      // Look out outline details of end
      int endLevel = 0;
      boolean endHidden = false;
      int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
      if (endOfOutlineGroupIdx < cols.sizeOfColArray()) {
        CTCol nextInfo = cols.getColArray(endOfOutlineGroupIdx + 1);
        if (isAdjacentBefore(cols.getColArray(endOfOutlineGroupIdx),
            nextInfo)) {
          endLevel = nextInfo.getOutlineLevel();
          endHidden = nextInfo.getHidden();
        }
      }
      // Look out outline details of start
      int startLevel = 0;
      boolean startHidden = false;
      int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup(idx);
      if (startOfOutlineGroupIdx > 0) {
        CTCol prevInfo = cols.getColArray(startOfOutlineGroupIdx - 1);

        if (isAdjacentBefore(prevInfo, cols
            .getColArray(startOfOutlineGroupIdx))) {
          startLevel = prevInfo.getOutlineLevel();
          startHidden = prevInfo.getHidden();
        }
View Full Code Here

      }
      return startHidden;
    }

    private int findColInfoIdx(int columnValue, int fromColInfoIdx) {
      CTCols cols = worksheet.getColsArray(0);

      if (columnValue < 0) {
        throw new IllegalArgumentException(
            "column parameter out of range: " + columnValue);
      }
      if (fromColInfoIdx < 0) {
        throw new IllegalArgumentException(
            "fromIdx parameter out of range: " + fromColInfoIdx);
      }

      for (int k = fromColInfoIdx; k < cols.sizeOfColArray(); k++) {
        CTCol ci = cols.getColArray(k);

        if (containsColumn(ci, columnValue)) {
          return k;
        }
View Full Code Here

     *
     * @param idx
     * @return a boolean represented if the column is collapsed
     */
    private boolean isColumnGroupCollapsed(int idx) {
      CTCols cols = worksheet.getColsArray(0);
      int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
      int nextColInfoIx = endOfOutlineGroupIdx + 1;
      if (nextColInfoIx >= cols.sizeOfColArray()) {
        return false;
      }
      CTCol nextColInfo = cols.getColArray(nextColInfoIx);

      CTCol col = cols.getColArray(endOfOutlineGroupIdx);
      if (!isAdjacentBefore(col, nextColInfo)) {
        return false;
      }

      return nextColInfo.getCollapsed();
View Full Code Here

        String cellRef = cellReference.formatAsString();
    getPane().setTopLeftCell(cellRef);
    }

    public void ungroupColumn(int fromColumn, int toColumn) {
        CTCols cols = worksheet.getColsArray(0);
        for (int index = fromColumn; index <= toColumn; index++) {
            CTCol col = columnHelper.getColumn(index, false);
            if (col != null) {
                short outlineLevel = col.getOutlineLevel();
                col.setOutlineLevel((short) (outlineLevel - 1));
View Full Code Here

    }

    protected void write(OutputStream out) throws IOException {

        if(worksheet.getColsArray().length == 1) {
            CTCols col = worksheet.getColsArray(0);
            CTCol[] cols = col.getColArray();
            if(cols.length == 0) {
                worksheet.setColsArray(null);
            }
        }
View Full Code Here

        XSSFSheet sheet = workbook.createSheet();

        //one level
        sheet.groupColumn((short) 2, (short) 7);
        sheet.groupColumn((short) 10, (short) 11);
        CTCols cols = sheet.getCTWorksheet().getColsArray(0);
        assertEquals(2, cols.sizeOfColArray());
        CTCol[] colArray = cols.getColArray();
        assertNotNull(colArray);
        assertEquals(2 + 1, colArray[0].getMin()); // 1 based
        assertEquals(7 + 1, colArray[0].getMax()); // 1 based
        assertEquals(1, colArray[0].getOutlineLevel());

        //two level
        sheet.groupColumn((short) 1, (short) 2);
        cols = sheet.getCTWorksheet().getColsArray(0);
        assertEquals(4, cols.sizeOfColArray());
        colArray = cols.getColArray();
        assertEquals(2, colArray[1].getOutlineLevel());

        //three level
        sheet.groupColumn((short) 6, (short) 8);
        sheet.groupColumn((short) 2, (short) 3);
        cols = sheet.getCTWorksheet().getColsArray(0);
        assertEquals(7, cols.sizeOfColArray());
        colArray = cols.getColArray();
        assertEquals(3, colArray[1].getOutlineLevel());
        assertEquals(3, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol());

        sheet.ungroupColumn((short) 8, (short) 10);
        colArray = cols.getColArray();
        //assertEquals(3, colArray[1].getOutlineLevel());

        sheet.ungroupColumn((short) 4, (short) 6);
        sheet.ungroupColumn((short) 2, (short) 2);
        colArray = cols.getColArray();
        assertEquals(4, colArray.length);
        assertEquals(2, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol());
    }
View Full Code Here

     */
    public void testSetColumnGroupCollapsed(){
      Workbook wb = new XSSFWorkbook();
      XSSFSheet sheet1 =(XSSFSheet) wb.createSheet();

      CTCols cols=sheet1.getCTWorksheet().getColsArray(0);
      assertEquals(0,cols.sizeOfColArray());

      sheet1.groupColumn( (short)4, (short)7 );
      sheet1.groupColumn( (short)9, (short)12 );

      assertEquals(2,cols.sizeOfColArray());

      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(true, cols.getColArray(1).isSetCollapsed());
      assertEquals(10, cols.getColArray(1).getMin()); // 1 based
      assertEquals(13, cols.getColArray(1).getMax()); // 1 based

      sheet1.groupColumn( (short)10, (short)11 );
      assertEquals(4,cols.sizeOfColArray());

      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(true, cols.getColArray(1).isSetCollapsed());
      assertEquals(10, cols.getColArray(1).getMin()); // 1 based
      assertEquals(10, cols.getColArray(1).getMax()); // 1 based
      assertEquals(false,cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(11, cols.getColArray(2).getMin()); // 1 based
      assertEquals(12, cols.getColArray(2).getMax()); // 1 based
      assertEquals(false,cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(13, cols.getColArray(3).getMin()); // 1 based
      assertEquals(13, cols.getColArray(3).getMax()); // 1 based

      // collapse columns - 1
      sheet1.setColumnGroupCollapsed( (short)5, true );
      assertEquals(5,cols.sizeOfColArray());

      assertEquals(true, cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(true, cols.getColArray(1).isSetCollapsed());
      assertEquals(9, cols.getColArray(1).getMin()); // 1 based
      assertEquals(9, cols.getColArray(1).getMax()); // 1 based
      assertEquals(false,cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(10, cols.getColArray(2).getMin()); // 1 based
      assertEquals(10, cols.getColArray(2).getMax()); // 1 based
      assertEquals(false,cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(11, cols.getColArray(3).getMin()); // 1 based
      assertEquals(12, cols.getColArray(3).getMax()); // 1 based
      assertEquals(false,cols.getColArray(4).isSetHidden());
      assertEquals(true, cols.getColArray(4).isSetCollapsed());
      assertEquals(13, cols.getColArray(4).getMin()); // 1 based
      assertEquals(13, cols.getColArray(4).getMax()); // 1 based


      // expand columns - 1
      sheet1.setColumnGroupCollapsed( (short)5, false );

      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(false,cols.getColArray(1).isSetCollapsed());
      assertEquals(9, cols.getColArray(1).getMin()); // 1 based
      assertEquals(9, cols.getColArray(1).getMax()); // 1 based
      assertEquals(false,cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(10, cols.getColArray(2).getMin()); // 1 based
      assertEquals(10, cols.getColArray(2).getMax()); // 1 based
      assertEquals(false,cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(11, cols.getColArray(3).getMin()); // 1 based
      assertEquals(12, cols.getColArray(3).getMax()); // 1 based
      assertEquals(false,cols.getColArray(4).isSetHidden());
      assertEquals(true, cols.getColArray(4).isSetCollapsed());
      assertEquals(13, cols.getColArray(4).getMin()); // 1 based
      assertEquals(13, cols.getColArray(4).getMax()); // 1 based


      //collapse - 2
      sheet1.setColumnGroupCollapsed( (short)9, true );
      assertEquals(6,cols.sizeOfColArray());
      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(false,cols.getColArray(1).isSetCollapsed());
      assertEquals(9, cols.getColArray(1).getMin()); // 1 based
      assertEquals(9, cols.getColArray(1).getMax()); // 1 based
      assertEquals(true, cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(10, cols.getColArray(2).getMin()); // 1 based
      assertEquals(10, cols.getColArray(2).getMax()); // 1 based
      assertEquals(true, cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(11, cols.getColArray(3).getMin()); // 1 based
      assertEquals(12, cols.getColArray(3).getMax()); // 1 based
      assertEquals(true, cols.getColArray(4).isSetHidden());
      assertEquals(true, cols.getColArray(4).isSetCollapsed());
      assertEquals(13, cols.getColArray(4).getMin()); // 1 based
      assertEquals(13, cols.getColArray(4).getMax()); // 1 based
      assertEquals(false,cols.getColArray(5).isSetHidden());
      assertEquals(true, cols.getColArray(5).isSetCollapsed());
      assertEquals(14, cols.getColArray(5).getMin()); // 1 based
      assertEquals(14, cols.getColArray(5).getMax()); // 1 based


      //expand - 2
      sheet1.setColumnGroupCollapsed( (short)9, false );
      assertEquals(6,cols.sizeOfColArray());
      assertEquals(14,cols.getColArray(5).getMin());

      //outline level 2: the line under ==> collapsed==True
      assertEquals(2,cols.getColArray(3).getOutlineLevel());
      assertEquals(true,cols.getColArray(4).isSetCollapsed());

      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(false,cols.getColArray(1).isSetCollapsed());
      assertEquals(9, cols.getColArray(1).getMin()); // 1 based
      assertEquals(9, cols.getColArray(1).getMax()); // 1 based
      assertEquals(false,cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(10, cols.getColArray(2).getMin()); // 1 based
      assertEquals(10, cols.getColArray(2).getMax()); // 1 based
      assertEquals(true, cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(11, cols.getColArray(3).getMin()); // 1 based
      assertEquals(12, cols.getColArray(3).getMax()); // 1 based
      assertEquals(false,cols.getColArray(4).isSetHidden());
      assertEquals(true, cols.getColArray(4).isSetCollapsed());
      assertEquals(13, cols.getColArray(4).getMin()); // 1 based
      assertEquals(13, cols.getColArray(4).getMax()); // 1 based
      assertEquals(false,cols.getColArray(5).isSetHidden());
      assertEquals(false,cols.getColArray(5).isSetCollapsed());
      assertEquals(14, cols.getColArray(5).getMin()); // 1 based
      assertEquals(14, cols.getColArray(5).getMax()); // 1 based

      //DOCUMENTARE MEGLIO IL DISCORSO DEL LIVELLO
      //collapse - 3
      sheet1.setColumnGroupCollapsed( (short)10, true );
      assertEquals(6,cols.sizeOfColArray());
      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(false,cols.getColArray(1).isSetCollapsed());
      assertEquals(9, cols.getColArray(1).getMin()); // 1 based
      assertEquals(9, cols.getColArray(1).getMax()); // 1 based
      assertEquals(false,cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(10, cols.getColArray(2).getMin()); // 1 based
      assertEquals(10, cols.getColArray(2).getMax()); // 1 based
      assertEquals(true, cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(11, cols.getColArray(3).getMin()); // 1 based
      assertEquals(12, cols.getColArray(3).getMax()); // 1 based
      assertEquals(false,cols.getColArray(4).isSetHidden());
      assertEquals(true, cols.getColArray(4).isSetCollapsed());
      assertEquals(13, cols.getColArray(4).getMin()); // 1 based
      assertEquals(13, cols.getColArray(4).getMax()); // 1 based
      assertEquals(false,cols.getColArray(5).isSetHidden());
      assertEquals(false,cols.getColArray(5).isSetCollapsed());
      assertEquals(14, cols.getColArray(5).getMin()); // 1 based
      assertEquals(14, cols.getColArray(5).getMax()); // 1 based


      //expand - 3
      sheet1.setColumnGroupCollapsed( (short)10, false );
      assertEquals(6,cols.sizeOfColArray());
      assertEquals(false,cols.getColArray(0).getHidden());
      assertEquals(false,cols.getColArray(5).getHidden());
      assertEquals(false,cols.getColArray(4).isSetCollapsed());

//    write out and give back
      // Save and re-load
      wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
      sheet1 = (XSSFSheet)wb.getSheetAt(0);
      assertEquals(6,cols.sizeOfColArray());

      assertEquals(false,cols.getColArray(0).isSetHidden());
      assertEquals(true, cols.getColArray(0).isSetCollapsed());
      assertEquals(5, cols.getColArray(0).getMin()); // 1 based
      assertEquals(8, cols.getColArray(0).getMax()); // 1 based
      assertEquals(false,cols.getColArray(1).isSetHidden());
      assertEquals(false,cols.getColArray(1).isSetCollapsed());
      assertEquals(9, cols.getColArray(1).getMin()); // 1 based
      assertEquals(9, cols.getColArray(1).getMax()); // 1 based
      assertEquals(false,cols.getColArray(2).isSetHidden());
      assertEquals(true, cols.getColArray(2).isSetCollapsed());
      assertEquals(10, cols.getColArray(2).getMin()); // 1 based
      assertEquals(10, cols.getColArray(2).getMax()); // 1 based
      assertEquals(false,cols.getColArray(3).isSetHidden());
      assertEquals(true, cols.getColArray(3).isSetCollapsed());
      assertEquals(11, cols.getColArray(3).getMin()); // 1 based
      assertEquals(12, cols.getColArray(3).getMax()); // 1 based
      assertEquals(false,cols.getColArray(4).isSetHidden());
      assertEquals(false,cols.getColArray(4).isSetCollapsed());
      assertEquals(13, cols.getColArray(4).getMin()); // 1 based
      assertEquals(13, cols.getColArray(4).getMax()); // 1 based
      assertEquals(false,cols.getColArray(5).isSetHidden());
      assertEquals(false,cols.getColArray(5).isSetCollapsed());
      assertEquals(14, cols.getColArray(5).getMin()); // 1 based
      assertEquals(14, cols.getColArray(5).getMax()); // 1 based
    }
View Full Code Here

        XSSFSheet xs = sheet;
        CTWorksheet cts = xs.getCTWorksheet();

        CTCols[] cols_s = cts.getColsArray();
        assertEquals(1, cols_s.length);
        CTCols cols = cols_s[0];
        assertEquals(1, cols.sizeOfColArray());
        CTCol col = cols.getColArray(0);

        // XML is 1 based, POI is 0 based
        assertEquals(2, col.getMin());
        assertEquals(2, col.getMax());
        assertEquals(22.0, col.getWidth(), 0.0);
        assertTrue(col.getCustomWidth());

        // Now set another
        sheet.setColumnWidth(3, 33 * 256);

        cols_s = cts.getColsArray();
        assertEquals(1, cols_s.length);
        cols = cols_s[0];
        assertEquals(2, cols.sizeOfColArray());

        col = cols.getColArray(0);
        assertEquals(2, col.getMin()); // POI 1
        assertEquals(2, col.getMax());
        assertEquals(22.0, col.getWidth(), 0.0);
        assertTrue(col.getCustomWidth());

        col = cols.getColArray(1);
        assertEquals(4, col.getMin()); // POI 3
        assertEquals(4, col.getMax());
        assertEquals(33.0, col.getWidth(), 0.0);
        assertTrue(col.getCustomWidth());
    }
View Full Code Here

TOP

Related Classes of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.