Search in sources :

Example 6 with CTCols

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.

the class TestColumnHelper method testAddCleanColIntoColsOverlapsCompletelyNested.

@Test
public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
    CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
    assertEquals(3, cols.sizeOfColArray());
    assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
    assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
    assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) Test(org.junit.Test)

Example 7 with CTCols

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.

the class TestColumnHelper method testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft.

@Test
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception {
    CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
    assertEquals(2, cols.sizeOfColArray());
    assertMinMaxHiddenBestFit(cols, 0, 1, 2, true, true);
    assertMinMaxHiddenBestFit(cols, 1, 3, 3, false, true);
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) Test(org.junit.Test)

Example 8 with CTCols

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.

the class TestColumnHelper method testCloneCol.

@Test
public void testCloneCol() {
    CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
    ColumnHelper helper = new ColumnHelper(worksheet);
    CTCols cols = CTCols.Factory.newInstance();
    CTCol col = CTCol.Factory.newInstance();
    col.setMin(2);
    col.setMax(8);
    col.setHidden(true);
    col.setWidth(13.4);
    CTCol newCol = helper.cloneCol(cols, col);
    assertEquals(2, newCol.getMin());
    assertEquals(8, newCol.getMax());
    assertTrue(newCol.getHidden());
    assertEquals(13.4, newCol.getWidth(), 0.0);
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol) Test(org.junit.Test)

Example 9 with CTCols

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.

the class TestColumnHelper method testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight.

@Test
public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception {
    CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
    assertEquals(2, cols.sizeOfColArray());
    assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
    assertMinMaxHiddenBestFit(cols, 1, 2, 3, true, true);
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) Test(org.junit.Test)

Example 10 with CTCols

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.

the class TestXSSFSheet method bug47804.

/**
     * Hiding a column included in a column span
     */
@Test
public void bug47804() throws IOException {
    XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("47804.xlsx");
    XSSFSheet sheet = wb1.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());
    // Column C
    sheet.setColumnHidden(2, true);
    // Column G
    sheet.setColumnHidden(6, true);
    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
    XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheetAt(0);
    assertTrue(sheet.isColumnHidden(2));
    assertTrue(sheet.isColumnHidden(6));
    assertFalse(sheet.isColumnHidden(1));
    assertFalse(sheet.isColumnHidden(3));
    assertFalse(sheet.isColumnHidden(4));
    assertFalse(sheet.isColumnHidden(5));
    wb2.close();
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Aggregations

CTCols (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols)27 Test (org.junit.Test)24 CTCol (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)23 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)6 CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)6 TreeSet (java.util.TreeSet)1