Search in sources :

Example 36 with CTCol

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

the class TestColumnHelper method testSetColumnAttributes.

@Test
public void testSetColumnAttributes() {
    CTCol col = CTCol.Factory.newInstance();
    col.setWidth(12);
    col.setHidden(true);
    CTCol newCol = CTCol.Factory.newInstance();
    assertEquals(0.0, newCol.getWidth(), 0.0);
    assertFalse(newCol.getHidden());
    ColumnHelper helper = new ColumnHelper(CTWorksheet.Factory.newInstance());
    helper.setColumnAttributes(col, newCol);
    assertEquals(12.0, newCol.getWidth(), 0.0);
    assertTrue(newCol.getHidden());
}
Also used : CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol) Test(org.junit.Test)

Example 37 with CTCol

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

the class TestColumnHelper method testGetOrCreateColumn.

@Test
public void testGetOrCreateColumn() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Sheet 1");
    ColumnHelper columnHelper = sheet.getColumnHelper();
    // Check POI 0 based, OOXML 1 based
    CTCol col = columnHelper.getOrCreateColumn1Based(3, false);
    assertNotNull(col);
    assertNull(columnHelper.getColumn(1, false));
    assertNotNull(columnHelper.getColumn(2, false));
    assertNotNull(columnHelper.getColumn1Based(3, false));
    assertNull(columnHelper.getColumn(3, false));
    CTCol col2 = columnHelper.getOrCreateColumn1Based(30, false);
    assertNotNull(col2);
    assertNull(columnHelper.getColumn(28, false));
    assertNotNull(columnHelper.getColumn(29, false));
    assertNotNull(columnHelper.getColumn1Based(30, false));
    assertNull(columnHelper.getColumn(30, false));
    workbook.close();
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Test(org.junit.Test)

Example 38 with CTCol

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

the class TestColumnHelper method testSortColumns.

@Test
public void testSortColumns() {
    CTCols cols1 = CTCols.Factory.newInstance();
    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);
    CTCol col3 = cols1.addNewCol();
    col3.setMin(13);
    col3.setMax(16750);
    assertEquals(3, cols1.sizeOfColArray());
    CTCol col4 = cols1.addNewCol();
    col4.setMin(8);
    col4.setMax(11);
    assertEquals(4, cols1.sizeOfColArray());
    CTCol col5 = cols1.addNewCol();
    col5.setMin(4);
    col5.setMax(5);
    assertEquals(5, cols1.sizeOfColArray());
    CTCol col6 = cols1.addNewCol();
    col6.setMin(8);
    col6.setMax(9);
    col6.setHidden(true);
    CTCol col7 = cols1.addNewCol();
    col7.setMin(6);
    col7.setMax(8);
    col7.setWidth(17.0);
    CTCol col8 = cols1.addNewCol();
    col8.setMin(25);
    col8.setMax(27);
    CTCol col9 = cols1.addNewCol();
    col9.setMin(20);
    col9.setMax(30);
    assertEquals(9, cols1.sizeOfColArray());
    assertEquals(20, cols1.getColArray(8).getMin());
    assertEquals(30, cols1.getColArray(8).getMax());
    ColumnHelper.sortColumns(cols1);
    assertEquals(9, cols1.sizeOfColArray());
    assertEquals(25, cols1.getColArray(8).getMin());
    assertEquals(27, cols1.getColArray(8).getMax());
}
Also used : CTCols(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols) 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