use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestXSSFColGrouping method testMergingOverlappingCols_OVERLAPS_1_WRAPS.
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_1_WRAPS
*/
@Test
public void testMergingOverlappingCols_OVERLAPS_1_WRAPS() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
CTCol col = cols.addNewCol();
col.setMin(2 + 1);
col.setMax(4 + 1);
col.setWidth(20);
col.setCustomWidth(true);
sheet.groupColumn((short) 1, (short) 5);
cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_WRAPS/cols:" + cols);
assertEquals(1, cols.getColArray(0).getOutlineLevel());
// 1 based
assertEquals(2, cols.getColArray(0).getMin());
// 1 based
assertEquals(2, cols.getColArray(0).getMax());
assertEquals(false, cols.getColArray(0).getCustomWidth());
assertEquals(1, cols.getColArray(1).getOutlineLevel());
// 1 based
assertEquals(3, cols.getColArray(1).getMin());
// 1 based
assertEquals(5, cols.getColArray(1).getMax());
assertEquals(true, cols.getColArray(1).getCustomWidth());
assertEquals(1, cols.getColArray(2).getOutlineLevel());
// 1 based
assertEquals(6, cols.getColArray(2).getMin());
// 1 based
assertEquals(6, cols.getColArray(2).getMax());
assertEquals(false, cols.getColArray(2).getCustomWidth());
assertEquals(3, cols.sizeOfColArray());
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_WRAPS");
sheet = wb2.getSheet("test");
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column " + i, 20 * 256, sheet.getColumnWidth(i));
}
wb2.close();
wb1.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestXSSFColGrouping method testMergingOverlappingCols_OVERLAPS_2_WRAPS.
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_2_WRAPS
*/
@Test
public void testMergingOverlappingCols_OVERLAPS_2_WRAPS() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
CTCol col = cols.addNewCol();
col.setMin(1 + 1);
col.setMax(4 + 1);
col.setWidth(20);
col.setCustomWidth(true);
sheet.groupColumn((short) 2, (short) 3);
sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_WRAPS/cols:" + cols);
assertEquals(0, cols.getColArray(0).getOutlineLevel());
// 1 based
assertEquals(2, cols.getColArray(0).getMin());
// 1 based
assertEquals(2, cols.getColArray(0).getMax());
assertEquals(true, cols.getColArray(0).getCustomWidth());
assertEquals(1, cols.getColArray(1).getOutlineLevel());
// 1 based
assertEquals(3, cols.getColArray(1).getMin());
// 1 based
assertEquals(4, cols.getColArray(1).getMax());
assertEquals(true, cols.getColArray(1).getCustomWidth());
assertEquals(0, cols.getColArray(2).getOutlineLevel());
// 1 based
assertEquals(5, cols.getColArray(2).getMin());
// 1 based
assertEquals(5, cols.getColArray(2).getMax());
assertEquals(true, cols.getColArray(2).getCustomWidth());
assertEquals(3, cols.sizeOfColArray());
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_WRAPS");
sheet = wb2.getSheet("test");
for (int i = 1; i <= 4; i++) {
assertEquals("Unexpected width of column " + i, 20 * 256, sheet.getColumnWidth(i));
}
wb2.close();
wb1.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestXSSFColGrouping method testNoColsWithoutWidthWhenGrouping.
/**
* Tests that POI doesn't produce "col" elements without "width" attribute.
* POI-52186
*/
@Test
public void testNoColsWithoutWidthWhenGrouping() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
sheet.groupColumn((short) 4, (short) 7);
sheet.groupColumn((short) 9, (short) 12);
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGrouping");
sheet = wb2.getSheet("test");
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
for (CTCol col : cols.getColArray()) {
assertTrue("Col width attribute is unset: " + col, col.isSetWidth());
}
wb2.close();
wb1.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestColumnHelper method testAddCleanColIntoCols.
@Test
public void testAddCleanColIntoCols() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
ColumnHelper helper = new ColumnHelper(worksheet);
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(9);
assertEquals(4, cols1.sizeOfColArray());
// No overlap
helper.addCleanColIntoCols(cols1, createCol(4, 5));
assertEquals(5, cols1.sizeOfColArray());
// Overlaps with 8 - 9 (overlap and after replacements required)
CTCol col6 = createCol(8, 11);
col6.setHidden(true);
helper.addCleanColIntoCols(cols1, col6);
assertEquals(6, cols1.sizeOfColArray());
// Overlaps with 8 - 9 (before and overlap replacements required)
CTCol col7 = createCol(6, 8);
col7.setWidth(17.0);
helper.addCleanColIntoCols(cols1, col7);
assertEquals(8, cols1.sizeOfColArray());
// Overlaps with 13 - 16750 (before, overlap and after replacements required)
helper.addCleanColIntoCols(cols1, createCol(20, 30));
assertEquals(10, cols1.sizeOfColArray());
// Overlaps with 20 - 30 (before, overlap and after replacements required)
helper.addCleanColIntoCols(cols1, createCol(25, 27));
// TODO - assert something interesting
assertEquals(12, cols1.sizeOfColArray());
assertEquals(1, cols1.getColArray(0).getMin());
assertEquals(16750, cols1.getColArray(11).getMax());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestColumnHelper method testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft.
@Test
public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception {
CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
assertEquals(3, cols.sizeOfColArray());
assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
}
Aggregations