import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
-import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
+import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
}
public short getBorderBottom() {
- return (short) (getBorderStyle(BorderSides.BOTTOM).intValue() - 1);
+ return getBorderStyleAsShort(BorderSide.BOTTOM);
}
public String getBorderBottomAsString() {
- return getBorderStyle(BorderSides.BOTTOM).toString();
+ return getBorderStyleAsString(BorderSide.BOTTOM);
}
public short getBorderLeft() {
- return (short) (getBorderStyle(BorderSides.LEFT).intValue() - 1);
+ return getBorderStyleAsShort(BorderSide.LEFT);
}
public String getBorderLeftAsString() {
- return getBorderStyle(BorderSides.LEFT).toString();
+ return getBorderStyleAsString(BorderSide.LEFT);
}
public short getBorderRight() {
- return (short) (getBorderStyle(BorderSides.RIGHT).intValue() - 1);
+ return getBorderStyleAsShort(BorderSide.RIGHT);
}
public String getBorderRightAsString() {
- return getBorderStyle(BorderSides.RIGHT).toString();
+ return getBorderStyleAsString(BorderSide.RIGHT);
}
public short getBorderTop() {
- return (short) (getBorderStyle(BorderSides.TOP).intValue() - 1);
+ return getBorderStyleAsShort(BorderSide.TOP);
}
public String getBorderTopAsString() {
- return getBorderStyle(BorderSides.TOP).toString();
+ return getBorderStyleAsString(BorderSide.TOP);
}
public short getBottomBorderColor() {
- return getBorderColorBySide(BorderSides.BOTTOM);
+ return getBorderColorIndexed(BorderSide.BOTTOM);
}
public short getDataFormat() {
}
public short getLeftBorderColor() {
- return getBorderColorBySide(BorderSides.LEFT);
+ return getBorderColorIndexed(BorderSide.LEFT);
}
public boolean getLocked() {
}
public short getRightBorderColor() {
- return getBorderColorBySide(BorderSides.RIGHT);
+ return getBorderColorIndexed(BorderSide.RIGHT);
}
public short getRotation() {
}
public short getTopBorderColor() {
- return getBorderColorBySide(BorderSides.TOP);
+ return getBorderColorIndexed(BorderSide.TOP);
}
public short getVerticalAlignment() {
}
public void setBorderBottom(short border) {
- // TODO Auto-generated method stub
-
+ setBorderBottomEnum(STBorderStyle.Enum.forInt(border));
+ }
+
+ public void setBorderBottomEnum(STBorderStyle.Enum style) {
+ getCellBorder().setBorderStyle(BorderSide.BOTTOM, style);
}
public void setBorderLeft(short border) {
- // TODO Auto-generated method stub
-
+ setBorderLeftEnum(STBorderStyle.Enum.forInt(border));
+ }
+
+ public void setBorderLeftEnum(STBorderStyle.Enum style) {
+ getCellBorder().setBorderStyle(BorderSide.LEFT, style);
}
public void setBorderRight(short border) {
- // TODO Auto-generated method stub
-
+ setBorderRightEnum(STBorderStyle.Enum.forInt(border));
+ }
+
+ public void setBorderRightEnum(STBorderStyle.Enum style) {
+ getCellBorder().setBorderStyle(BorderSide.RIGHT, style);
}
public void setBorderTop(short border) {
- // TODO Auto-generated method stub
-
+ setBorderTopEnum(STBorderStyle.Enum.forInt(border));
+ }
+
+ public void setBorderTopEnum(STBorderStyle.Enum style) {
+ getCellBorder().setBorderStyle(BorderSide.TOP, style);
}
public void setBottomBorderColor(short color) {
- // TODO Auto-generated method stub
-
+ setBorderColorIndexed(BorderSide.BOTTOM, color);
}
public void setDataFormat(short fmt) {
}
public void setLeftBorderColor(short color) {
- // TODO Auto-generated method stub
-
+ setBorderColorIndexed(BorderSide.LEFT, color);
}
public void setLocked(boolean locked) {
}
public void setRightBorderColor(short color) {
- // TODO Auto-generated method stub
-
+ setBorderColorIndexed(BorderSide.RIGHT, color);
}
public void setRotation(short rotation) {
}
public void setTopBorderColor(short color) {
- // TODO Auto-generated method stub
-
+ setBorderColorIndexed(BorderSide.TOP, color);
}
public void setVerticalAlignment(short align) {
}
return (int) cellStyleXf.getFillId();
}
-
- private STBorderStyle.Enum getBorderStyle(BorderSides side) {
- return getCellBorder().getBorderStyle(side);
- }
-
- private short getBorderColorBySide(BorderSides side) {
- return (short) getCellBorder().getBorderColor(side).getIndexed();
- }
private int getFontId() {
if (cellXf.isSetFontId()) {
}
return cellXf.getAlignment();
}
+
+ private short getBorderColorIndexed(BorderSide side) {
+ return (short) getBorderColor(side).getIndexed();
+ }
+
+ private XSSFColor getBorderColor(BorderSide side) {
+ return getCellBorder().getBorderColor(side);
+ }
+
+ private void setBorderColorIndexed(BorderSide side, long color) {
+ getBorderColor(side).setIndexed(color);
+ }
+
+ private short getBorderStyleAsShort(BorderSide side) {
+ return (short) (getBorderStyle(side).intValue() - 1);
+ }
+
+ private String getBorderStyleAsString(BorderSide side) {
+ return getBorderStyle(side).toString();
+ }
+
+ private STBorderStyle.Enum getBorderStyle(BorderSide side) {
+ return getCellBorder().getBorderStyle(side);
+ }
}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
border = CTBorder.Factory.newInstance();
}
- public static enum BorderSides {
+ public static enum BorderSide {
TOP, RIGHT, BOTTOM, LEFT
}
return borders.size() - 1;
}
- public org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum getBorderStyle(BorderSides side) {
+ public STBorderStyle.Enum getBorderStyle(BorderSide side) {
return getBorder(side).getStyle();
}
- public XSSFColor getBorderColor(BorderSides side) {
+ public void setBorderStyle(BorderSide side, STBorderStyle.Enum style) {
+ getBorder(side).setStyle(style);
+ }
+
+ public XSSFColor getBorderColor(BorderSide side) {
CTBorderPr borderPr = getBorder(side);
if (!borderPr.isSetColor()) {
borderPr.addNewColor();
return new XSSFColor(getBorder(side).getColor());
}
- private CTBorderPr getBorder(BorderSides side) {
+ private CTBorderPr getBorder(BorderSide side) {
switch (side) {
case TOP: return border.getTop();
case RIGHT: return border.getRight();
cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable);
}
- public void testGetBorderBottom() {
+ public void testGetSetBorderBottom() {
ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
assertEquals((short)1, cellStyle.getBorderBottom());
+ cellStyle.setBorderBottom((short) 2);
+ assertEquals(STBorderStyle.THIN, ctBorderA.getBottom().getStyle());
+ cellStyle.setBorderBottomEnum(STBorderStyle.THICK);
+ assertEquals(6, ctBorderA.getBottom().getStyle().intValue());
}
public void testGetBorderBottomAsString() {
assertEquals("thin", cellStyle.getBorderBottomAsString());
}
- public void testGetBorderRight() {
+ public void testGetSetBorderRight() {
ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
assertEquals((short)2, cellStyle.getBorderRight());
+ cellStyle.setBorderRight((short) 2);
+ assertEquals(STBorderStyle.THIN, ctBorderA.getRight().getStyle());
+ cellStyle.setBorderRightEnum(STBorderStyle.THICK);
+ assertEquals(6, ctBorderA.getRight().getStyle().intValue());
}
public void testGetBorderRightAsString() {
assertEquals("medium", cellStyle.getBorderRightAsString());
}
- public void testGetBorderLeft() {
+ public void testGetSetBorderLeft() {
ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
assertEquals((short)3, cellStyle.getBorderLeft());
+ cellStyle.setBorderLeft((short) 2);
+ assertEquals(STBorderStyle.THIN, ctBorderA.getLeft().getStyle());
+ cellStyle.setBorderLeftEnum(STBorderStyle.THICK);
+ assertEquals(6, ctBorderA.getLeft().getStyle().intValue());
}
public void testGetBorderLeftAsString() {
assertEquals("dashed", cellStyle.getBorderLeftAsString());
}
- public void testGetBorderTop() {
+ public void testGetSetBorderTop() {
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
assertEquals((short)7, cellStyle.getBorderTop());
+ cellStyle.setBorderTop((short) 2);
+ assertEquals(STBorderStyle.THIN, ctBorderA.getTop().getStyle());
+ cellStyle.setBorderTopEnum(STBorderStyle.THICK);
+ assertEquals(6, ctBorderA.getTop().getStyle().intValue());
}
- public void testGetTopBottomAsString() {
+ public void testGetBorderTopAsString() {
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
assertEquals("hair", cellStyle.getBorderTopAsString());
}
package org.apache.poi.xssf.usermodel.extensions;
-import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
right.setStyle(STBorderStyle.NONE);
bottom.setStyle(STBorderStyle.THIN);
XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);
- assertEquals("dashDot", cellBorderStyle.getBorderStyle(BorderSides.TOP).toString());
- assertEquals("none", cellBorderStyle.getBorderStyle(BorderSides.RIGHT).toString());
- assertEquals(1, cellBorderStyle.getBorderStyle(BorderSides.RIGHT).intValue());
- assertEquals("thin", cellBorderStyle.getBorderStyle(BorderSides.BOTTOM).toString());
- assertEquals(2, cellBorderStyle.getBorderStyle(BorderSides.BOTTOM).intValue());
+ assertEquals("dashDot", cellBorderStyle.getBorderStyle(BorderSide.TOP).toString());
+ assertEquals("none", cellBorderStyle.getBorderStyle(BorderSide.RIGHT).toString());
+ assertEquals(1, cellBorderStyle.getBorderStyle(BorderSide.RIGHT).intValue());
+ assertEquals("thin", cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).toString());
+ assertEquals(2, cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).intValue());
}
}