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()); }
public void testGetSetColDefaultStyle() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); CTWorksheet ctWorksheet = sheet.getCTWorksheet(); ColumnHelper columnHelper = sheet.getColumnHelper(); // POI column 3, OOXML column 4 CTCol col = columnHelper.getOrCreateColumn1Based(4, false); assertNotNull(col); assertNotNull(columnHelper.getColumn(3, false)); columnHelper.setColDefaultStyle(3, 2); assertEquals(2, columnHelper.getColDefaultStyle(3)); assertEquals(-1, columnHelper.getColDefaultStyle(4)); StylesTable stylesTable = workbook.getStylesSource(); CTXf cellXf = CTXf.Factory.newInstance(); cellXf.setFontId(0); cellXf.setFillId(0); cellXf.setBorderId(0); cellXf.setNumFmtId(0); cellXf.setXfId(0); stylesTable.putCellXf(cellXf); CTCol col_2 = ctWorksheet.getColsArray(0).addNewCol(); col_2.setMin(10); col_2.setMax(12); col_2.setStyle(1); assertEquals(1, columnHelper.getColDefaultStyle(11)); XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null); columnHelper.setColDefaultStyle(11, cellStyle); assertEquals(0, col_2.getStyle()); assertEquals(1, columnHelper.getColDefaultStyle(10)); }
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)); }
public void testGetOrCreateColumn() { 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)); }