use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method setCustomWidth.
public void setCustomWidth(long index, boolean bestFit) {
CTCol col = getOrCreateColumn1Based(index + 1, true);
col.setCustomWidth(bestFit);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class ColumnHelper method getOrCreateColumn1Based.
/**
* Return the CTCol at the given (0 based) column index,
* creating it if required.
*/
protected CTCol getOrCreateColumn1Based(long index1, boolean splitColumns) {
CTCol col = getColumn1Based(index1, splitColumns);
if (col == null) {
col = worksheet.getColsArray(0).addNewCol();
col.setMin(index1);
col.setMax(index1);
}
return col;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class TestXSSFColGrouping method testMergingOverlappingCols_OVERLAPS_2_MINOR.
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_2_MINOR
*/
@Test
public void testMergingOverlappingCols_OVERLAPS_2_MINOR() 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) 3);
cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_MINOR/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(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_MINOR");
sheet = wb2.getSheet("test");
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column " + i, 20 * 256, sheet.getColumnWidth(i));
}
assertEquals("Unexpected width of column " + 1, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(1));
wb2.close();
wb1.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol in project poi by apache.
the class TestXSSFColGrouping method testNoColsWithoutWidthWhenGroupingAndCollapsing.
/**
* Tests that POI doesn't produce "col" elements without "width" attribute.
* POI-52186
*/
@Test
public void testNoColsWithoutWidthWhenGroupingAndCollapsing() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet = wb1.createSheet("test");
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
sheet.groupColumn((short) 4, (short) 5);
sheet.setColumnGroupCollapsed(4, true);
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols);
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
sheet = wb2.getSheet("test");
for (int i = 4; i <= 5; i++) {
assertEquals("Unexpected width of column " + i, 5000, sheet.getColumnWidth(i));
}
cols = sheet.getCTWorksheet().getColsArray(0);
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.CTCol in project poi by apache.
the class TestXSSFColGrouping method testMergingOverlappingCols_OVERLAPS_1_MINOR.
/**
* Test the cols element is correct in case of NumericRanges.OVERLAPS_1_MINOR
*/
@Test
public void testMergingOverlappingCols_OVERLAPS_1_MINOR() 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) 3, (short) 5);
cols = sheet.getCTWorksheet().getColsArray(0);
logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_MINOR/cols:" + cols);
assertEquals(0, cols.getColArray(0).getOutlineLevel());
// 1 based
assertEquals(3, cols.getColArray(0).getMin());
// 1 based
assertEquals(3, cols.getColArray(0).getMax());
assertEquals(true, cols.getColArray(0).getCustomWidth());
assertEquals(1, cols.getColArray(1).getOutlineLevel());
// 1 based
assertEquals(4, 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_MINOR");
sheet = wb2.getSheet("test");
for (int i = 2; i <= 4; i++) {
assertEquals("Unexpected width of column " + i, 20 * 256, sheet.getColumnWidth(i));
}
assertEquals("Unexpected width of column " + 5, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(5));
wb2.close();
wb1.close();
}
Aggregations