use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols 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());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols in project poi by apache.
the class TestXSSFBugs method bug51037.
/**
* Default Column style
*/
@Test
public void bug51037() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s = wb.createSheet();
CellStyle defaultStyle = wb.getCellStyleAt((short) 0);
assertEquals(0, defaultStyle.getIndex());
CellStyle blueStyle = wb.createCellStyle();
blueStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
blueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
assertEquals(1, blueStyle.getIndex());
CellStyle pinkStyle = wb.createCellStyle();
pinkStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
pinkStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
assertEquals(2, pinkStyle.getIndex());
// Starts empty
assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
CTCols cols = s.getCTWorksheet().getColsArray(0);
assertEquals(0, cols.sizeOfColArray());
// Add some rows and columns
XSSFRow r1 = s.createRow(0);
XSSFRow r2 = s.createRow(1);
r1.createCell(0);
r1.createCell(2);
r2.createCell(0);
r2.createCell(3);
// Check no style is there
assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
assertEquals(0, cols.sizeOfColArray());
assertEquals(defaultStyle, s.getColumnStyle(0));
assertEquals(defaultStyle, s.getColumnStyle(2));
assertEquals(defaultStyle, s.getColumnStyle(3));
// Apply the styles
s.setDefaultColumnStyle(0, pinkStyle);
s.setDefaultColumnStyle(3, blueStyle);
// Check
assertEquals(pinkStyle, s.getColumnStyle(0));
assertEquals(defaultStyle, s.getColumnStyle(2));
assertEquals(blueStyle, s.getColumnStyle(3));
assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
assertEquals(2, cols.sizeOfColArray());
assertEquals(1, cols.getColArray(0).getMin());
assertEquals(1, cols.getColArray(0).getMax());
assertEquals(pinkStyle.getIndex(), cols.getColArray(0).getStyle());
assertEquals(4, cols.getColArray(1).getMin());
assertEquals(4, cols.getColArray(1).getMax());
assertEquals(blueStyle.getIndex(), cols.getColArray(1).getStyle());
// Save, re-load and re-check
XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
s = wbBack.getSheetAt(0);
defaultStyle = wbBack.getCellStyleAt(defaultStyle.getIndex());
blueStyle = wbBack.getCellStyleAt(blueStyle.getIndex());
pinkStyle = wbBack.getCellStyleAt(pinkStyle.getIndex());
assertEquals(pinkStyle, s.getColumnStyle(0));
assertEquals(defaultStyle, s.getColumnStyle(2));
assertEquals(blueStyle, s.getColumnStyle(3));
wbBack.close();
}
Aggregations