use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.
the class TestXSSFCellStyle method testGetSetBorderRight.
@Test
public void testGetSetBorderRight() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderRightEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
int borderId = (int) cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getRight().getStyle());
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <right> element
cellStyle.setBorderRight(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int) cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertFalse(ctBorder.isSetRight());
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.
the class TestXSSFCellStyle method testGetSetBorderLeft.
@Test
public void testGetSetBorderLeft() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderLeftEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
int borderId = (int) cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getLeft().getStyle());
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <left> element
cellStyle.setBorderLeft(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int) cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertFalse(ctBorder.isSetLeft());
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.
the class TestXSSFCellStyle method testGetSetLeftBorderColor.
@Test
public void testGetSetLeftBorderColor() {
//defaults
assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getLeftBorderColor());
assertNull(cellStyle.getLeftBorderXSSFColor());
int num = stylesTable.getBorders().size();
XSSFColor clr;
//setting indexed color
cellStyle.setLeftBorderColor(IndexedColors.BLUE_GREY.getIndex());
assertEquals(IndexedColors.BLUE_GREY.getIndex(), cellStyle.getLeftBorderColor());
clr = cellStyle.getLeftBorderXSSFColor();
assertTrue(clr.getCTColor().isSetIndexed());
assertEquals(IndexedColors.BLUE_GREY.getIndex(), clr.getIndexed());
//a new border was added to the styles table
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
int borderId = (int) cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(IndexedColors.BLUE_GREY.getIndex(), ctBorder.getLeft().getColor().getIndexed());
//setting XSSFColor
num = stylesTable.getBorders().size();
clr = new XSSFColor(java.awt.Color.CYAN);
cellStyle.setLeftBorderColor(clr);
assertEquals(clr.getCTColor().toString(), cellStyle.getLeftBorderXSSFColor().getCTColor().toString());
byte[] rgb = cellStyle.getLeftBorderXSSFColor().getRGB();
assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
//another border was added to the styles table
assertEquals(num + 1, stylesTable.getBorders().size());
//passing null unsets the color
cellStyle.setLeftBorderColor(null);
assertNull(cellStyle.getLeftBorderXSSFColor());
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.
the class TestXSSFCellStyle method testGetSetBorderNone.
// Border Styles, in BorderStyle/STBorderStyle enum order
@Test
public void testGetSetBorderNone() {
cellStyle.setBorderTop(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum());
int borderId = (int) cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertNull(ctBorder.getTop());
// no border style and STBorderStyle.NONE are equivalent
// POI prefers to unset the border style than explicitly set it STBorderStyle.NONE
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder in project poi by apache.
the class TestXSSFCellStyle method testGetSetBorderTop.
@Test
public void testGetSetBorderTop() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
int borderId = (int) cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
num = stylesTable.getBorders().size();
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
//setting border to none removes the <top> element
cellStyle.setBorderTop(BorderStyle.NONE);
assertEquals(num, stylesTable.getBorders().size());
borderId = (int) cellStyle.getCoreXf().getBorderId();
ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
assertFalse(ctBorder.isSetTop());
}
Aggregations