Search in sources :

Example 31 with CTCol

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

the class TestColumnHelper method assertMinMaxHiddenBestFit.

private static void assertMinMaxHiddenBestFit(CTCols cols, int index, int min, int max, boolean hidden, boolean bestFit) {
    CTCol col = cols.getColArray(index);
    assertEquals(min, col.getMin());
    assertEquals(max, col.getMax());
    assertEquals(hidden, col.getHidden());
    assertEquals(bestFit, col.getBestFit());
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Example 32 with CTCol

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

the class TestColumnHelper method testGetColumn.

@Test
public void testGetColumn() {
    CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
    CTCols cols1 = worksheet.addNewCols();
    CTCol col1 = cols1.addNewCol();
    col1.setMin(1);
    col1.setMax(1);
    col1.setWidth(88);
    col1.setHidden(true);
    CTCol col2 = cols1.addNewCol();
    col2.setMin(2);
    col2.setMax(3);
    CTCols cols2 = worksheet.addNewCols();
    CTCol col4 = cols2.addNewCol();
    col4.setMin(3);
    col4.setMax(6);
    // Remember - POI column 0 == OOXML column 1
    ColumnHelper helper = new ColumnHelper(worksheet);
    assertNotNull(helper.getColumn(0, false));
    assertNotNull(helper.getColumn(1, false));
    assertEquals(88.0, helper.getColumn(0, false).getWidth(), 0.0);
    assertEquals(0.0, helper.getColumn(1, false).getWidth(), 0.0);
    assertTrue(helper.getColumn(0, false).getHidden());
    assertFalse(helper.getColumn(1, false).getHidden());
    assertNull(helper.getColumn(99, false));
    assertNotNull(helper.getColumn(5, false));
}
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 33 with CTCol

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

the class TestCTColComparator method testArraysSort.

public void testArraysSort() {
    CTCol o1 = CTCol.Factory.newInstance();
    o1.setMin(1);
    o1.setMax(10);
    CTCol o2 = CTCol.Factory.newInstance();
    o2.setMin(11);
    o2.setMax(12);
    assertEquals(-1, CTColComparator.BY_MIN_MAX.compare(o1, o2));
    CTCol o3 = CTCol.Factory.newInstance();
    o3.setMin(5);
    o3.setMax(80);
    CTCol o4 = CTCol.Factory.newInstance();
    o4.setMin(5);
    o4.setMax(8);
    assertEquals(1, CTColComparator.BY_MIN_MAX.compare(o3, o4));
    CTCol[] cols = new CTCol[4];
    cols[0] = o1;
    cols[1] = o2;
    cols[2] = o3;
    cols[3] = o4;
    assertEquals(80, cols[2].getMax());
    assertEquals(8, cols[3].getMax());
    Arrays.sort(cols, CTColComparator.BY_MIN_MAX);
    assertEquals(12, cols[3].getMax());
    assertEquals(8, cols[1].getMax());
    assertEquals(80, cols[2].getMax());
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Example 34 with CTCol

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

the class TestCTColComparator method testCompare.

public void testCompare() {
    CTCol o1 = CTCol.Factory.newInstance();
    o1.setMin(1);
    o1.setMax(10);
    CTCol o2 = CTCol.Factory.newInstance();
    o2.setMin(11);
    o2.setMax(12);
    assertEquals(-1, CTColComparator.BY_MIN_MAX.compare(o1, o2));
    CTCol o3 = CTCol.Factory.newInstance();
    o3.setMin(5);
    o3.setMax(8);
    CTCol o4 = CTCol.Factory.newInstance();
    o4.setMin(5);
    o4.setMax(80);
    assertEquals(-1, CTColComparator.BY_MIN_MAX.compare(o3, o4));
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)

Example 35 with CTCol

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

the class TestColumnHelper method testCleanColumns.

@Test
public void testCleanColumns() {
    CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
    CTCols cols1 = worksheet.addNewCols();
    CTCol col1 = cols1.addNewCol();
    col1.setMin(1);
    col1.setMax(1);
    col1.setWidth(88);
    col1.setHidden(true);
    CTCol col2 = cols1.addNewCol();
    col2.setMin(2);
    col2.setMax(3);
    CTCols cols2 = worksheet.addNewCols();
    CTCol col4 = cols2.addNewCol();
    col4.setMin(13);
    col4.setMax(16384);
    // Test cleaning cols
    assertEquals(2, worksheet.sizeOfColsArray());
    int count = countColumns(worksheet);
    assertEquals(16375, count);
    // Clean columns and test a clean worksheet
    ColumnHelper helper = new ColumnHelper(worksheet);
    assertEquals(1, worksheet.sizeOfColsArray());
    count = countColumns(worksheet);
    assertEquals(16375, count);
    // Remember - POI column 0 == OOXML column 1
    assertEquals(88.0, helper.getColumn(0, false).getWidth(), 0.0);
    assertTrue(helper.getColumn(0, false).getHidden());
    assertEquals(0.0, helper.getColumn(1, false).getWidth(), 0.0);
    assertFalse(helper.getColumn(1, false).getHidden());
}
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)

Aggregations

CTCol (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)38 Test (org.junit.Test)19 CTCols (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols)18 CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)7 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)5 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 StylesTable (org.apache.poi.xssf.model.StylesTable)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 ColumnHelper (org.apache.poi.xssf.usermodel.helpers.ColumnHelper)1 CTXf (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf)1