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

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


    }

    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;
        }
        idx++;
        columnInfo = nextColumnInfo;
      }
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);
            }
          } else {
            nestedGroup = true;
          }
        }
View Full Code Here

      // 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();
        }

      }
      if (endLevel > startLevel) {
        return endHidden;
View Full Code Here

        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;
        }

        if (ci.getMin() > fromColInfoIdx) {
          break;
        }

      }
      return -1;
View Full Code Here

      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

    }

    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));
                index = (int) col.getMax();

                if (col.getOutlineLevel() <= 0) {
                    int colIndex = columnHelper.getIndexOfColumn(cols, col);
                    worksheet.getColsArray(0).removeCol(colIndex);
                }
            }
        }
View Full Code Here

        sheet.createRow(0).createCell(13).setCellValue("test");

        sheet.autoSizeColumn(13);

        ColumnHelper columnHelper = sheet.getColumnHelper();
        CTCol col = columnHelper.getColumn(13, false);
        assertTrue(col.getBestFit());
    }
View Full Code Here

        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

        //  <col min="1" max="5" width="15.77734375" customWidth="1"/>
        //</cols>

        //a span of columns [1,5]
        assertEquals(1, cols.sizeOfColArray());
        CTCol col = cols.getColArray(0);
        assertEquals(1, col.getMin());
        assertEquals(5, col.getMax());
        double swidth = 15.77734375; //width of columns in the span
        assertEquals(swidth, col.getWidth());

        for (int i = 0; i < 5; i++) {
            assertEquals((int)(swidth*256), sheet.getColumnWidth(i));
        }

View Full Code Here

    public void test47804() {
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47804.xlsx");
        XSSFSheet sheet = wb.getSheetAt(0);
        CTCols cols = sheet.getCTWorksheet().getColsArray(0);
        assertEquals(2, cols.sizeOfColArray());
        CTCol col;
        //<cols>
        //  <col min="2" max="4" width="12" customWidth="1"/>
        //  <col min="7" max="7" width="10.85546875" customWidth="1"/>
        //</cols>

        //a span of columns [2,4]
        col = cols.getColArray(0);
        assertEquals(2, col.getMin());
        assertEquals(4, col.getMax());
        //individual column
        col = cols.getColArray(1);
        assertEquals(7, col.getMin());
        assertEquals(7, col.getMax());

        sheet.setColumnHidden(2, true); // Column C
        sheet.setColumnHidden(6, true); // Column G

        assertTrue(sheet.isColumnHidden(2));
        assertTrue(sheet.isColumnHidden(6));

        //other columns but C and G are not hidden
        assertFalse(sheet.isColumnHidden(1));
        assertFalse(sheet.isColumnHidden(3));
        assertFalse(sheet.isColumnHidden(4));
        assertFalse(sheet.isColumnHidden(5));

        //the check below failed prior to fix of Bug #47804
        ColumnHelper.sortColumns(cols);
        //the span is now splitted into three parts
        //<cols>
        //  <col min="2" max="2" customWidth="true" width="12.0" />
        //  <col min="3" max="3" customWidth="true" width="12.0" hidden="true"/>
        //  <col min="4" max="4" customWidth="true" width="12.0"/>
        //  <col min="7" max="7" customWidth="true" width="10.85546875" hidden="true"/>
        //</cols>

        assertEquals(4, cols.sizeOfColArray());
        col = cols.getColArray(0);
        assertEquals(2, col.getMin());
        assertEquals(2, col.getMax());
        col = cols.getColArray(1);
        assertEquals(3, col.getMin());
        assertEquals(3, col.getMax());
        col = cols.getColArray(2);
        assertEquals(4, col.getMin());
        assertEquals(4, col.getMax());
        col = cols.getColArray(3);
        assertEquals(7, col.getMin());
        assertEquals(7, col.getMax());

        //serialize and check again
        wb = getTestDataProvider().writeOutAndReadBack(wb);
        sheet = wb.getSheetAt(0);
        assertTrue(sheet.isColumnHidden(2));
View Full Code Here

TOP

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

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.