import org.apache.poi.ss.usermodel.StylesSource;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.model.StylesTable;
+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.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment.Enum;
public class XSSFCellStyle implements CellStyle {
private XSSFCellBorder cellBorder;
private XSSFCellFill cellFill;
private XSSFFont font;
+ private XSSFCellAlignment cellAlignment;
/**
* Creates a Cell Style from the supplied parts
}
public short getAlignment() {
- // TODO Auto-generated method stub
- return 0;
+ return (short)getAlignmentEnum().intValue();
+ }
+
+ public STHorizontalAlignment.Enum getAlignmentEnum() {
+ return getCellAlignment().getHorizontal();
}
public short getBorderBottom() {
}
public Font getFont(Workbook parentWorkbook) {
- // TODO Auto-generated method stub
- return null;
+ return getFont();
}
public Font getFont() {
}
public short getFontIndex() {
- // TODO Auto-generated method stub
- return 0;
+ return (short) getFontId();
}
public boolean getHidden() {
- // TODO Auto-generated method stub
- return false;
+ return getCellProtection().getHidden();
}
public short getIndention() {
- // TODO Auto-generated method stub
- return 0;
+ return (short) getCellAlignment().getIndent();
}
public short getIndex() {
}
public boolean getLocked() {
- // TODO Auto-generated method stub
- return false;
+ return getCellProtection().getLocked();
}
public short getRightBorderColor() {
}
public short getRotation() {
- // TODO Auto-generated method stub
- return 0;
+ return (short) getCellAlignment().getTextRotation();
}
public short getTopBorderColor() {
}
public short getVerticalAlignment() {
- // TODO Auto-generated method stub
- return 0;
+ return (short) getVerticalAlignmentEnum().intValue();
+ }
+
+ public STVerticalAlignment.Enum getVerticalAlignmentEnum() {
+ return getCellAlignment().getVertical();
}
public boolean getWrapText() {
- // TODO Auto-generated method stub
- return false;
+ return getCellAlignment().getWrapText();
}
public void setAlignment(short align) {
- // TODO Auto-generated method stub
-
+ getCellAlignment().setHorizontal(STHorizontalAlignment.Enum.forInt(align));
+ }
+
+ public void setAlignementEnum(STHorizontalAlignment.Enum align) {
+ getCellAlignment().setHorizontal(align);
}
public void setBorderBottom(short border) {
}
public void setHidden(boolean hidden) {
- // TODO Auto-generated method stub
-
+ getCellProtection().setHidden(hidden);
}
public void setIndention(short indent) {
- // TODO Auto-generated method stub
-
+ getCellAlignment().setIndent(indent);
}
public void setLeftBorderColor(short color) {
}
public void setLocked(boolean locked) {
- // TODO Auto-generated method stub
-
+ getCellProtection().setLocked(locked);
}
public void setRightBorderColor(short color) {
}
public void setVerticalAlignment(short align) {
- // TODO Auto-generated method stub
-
+ setVerticalAlignmentEnum(STVerticalAlignment.Enum.forInt(align));
+ }
+
+ public void setVerticalAlignmentEnum(STVerticalAlignment.Enum align) {
+ getCellAlignment().setVertical(align);
}
public void setWrapText(boolean wrapped) {
return (int) cellStyleXf.getFillId();
}
- private Enum getBorderStyle(BorderSides side) {
+ private STBorderStyle.Enum getBorderStyle(BorderSides side) {
return getCellBorder().getBorderStyle(side);
}
}
return (int) cellStyleXf.getFontId();
}
+
+ private CTCellProtection getCellProtection() {
+ if (cellXf.getProtection() == null) {
+ CTCellProtection protection = cellXf.addNewProtection();
+ }
+ return cellXf.getProtection();
+ }
+
+ private XSSFCellAlignment getCellAlignment() {
+ if (this.cellAlignment == null) {
+ this.cellAlignment = new XSSFCellAlignment(getCTCellAlignment());
+ }
+ return this.cellAlignment;
+ }
+
+ private CTCellAlignment getCTCellAlignment() {
+ if (cellXf.getAlignment() == null) {
+ cellXf.setAlignment(CTCellAlignment.Factory.newInstance());
+ }
+ return cellXf.getAlignment();
+ }
}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment.Enum;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
public class XSSFCellAlignment {
this.cellAlignement = cellAlignment;
}
- public Enum getHorizontal() {
+ public STVerticalAlignment.Enum getVertical() {
+ if (cellAlignement.getVertical() == null) {
+ cellAlignement.setVertical(STVerticalAlignment.TOP);
+ }
+ return cellAlignement.getVertical();
+ }
+
+ public void setVertical(STVerticalAlignment.Enum vertical) {
+ cellAlignement.setVertical(vertical);
+ }
+
+ public STHorizontalAlignment.Enum getHorizontal() {
+ if (cellAlignement.getHorizontal() == null) {
+ cellAlignement.setHorizontal(STHorizontalAlignment.GENERAL);
+ }
return cellAlignement.getHorizontal();
}
public void setIndent(long indent) {
cellAlignement.setIndent(indent);
}
+
+ public long getTextRotation() {
+ return cellAlignement.getTextRotation();
+ }
+
+ public boolean getWrapText() {
+ return cellAlignement.getWrapText();
+ }
}
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
public class TestXSSFCellStyle extends TestCase {
private CTFont ctFont;
private CTXf cellStyleXf;
private CTXf cellXf;
+ private CTCellXfs cellXfs;
private XSSFCellStyle cellStyle;
+ private CTStylesheet ctStylesheet;
public void setUp() {
stylesTable = new StylesTable();
- CTStylesheet ctStylesheet = stylesTable._getRawStylesheet();
+ ctStylesheet = stylesTable._getRawStylesheet();
// Until we do XSSFBorder properly, cheat
ctBorderA = CTBorder.Factory.newInstance();
cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
cellStyleXf.setBorderId(0);
- cellXf = ctStylesheet.addNewCellXfs().addNewXf();
+ cellXfs = ctStylesheet.addNewCellXfs();
+ cellXf = cellXfs.addNewXf();
cellXf.setXfId(0);
cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable);
}
public void testGetFont() {
assertNotNull(cellStyle.getFont());
}
+
+ public void testGetSetHidden() {
+ assertFalse(cellStyle.getHidden());
+ cellXf.getProtection().setHidden(true);
+ assertTrue(cellStyle.getHidden());
+ cellStyle.setHidden(false);
+ assertFalse(cellStyle.getHidden());
+ }
+
+ public void testGetSetLocked() {
+ assertFalse(cellStyle.getLocked());
+ cellXf.getProtection().setLocked(true);
+ assertTrue(cellStyle.getLocked());
+ cellStyle.setLocked(false);
+ assertFalse(cellStyle.getLocked());
+ }
+
+ public void testGetSetIndent() {
+ assertEquals((short)0, cellStyle.getIndention());
+ cellXf.getAlignment().setIndent(3);
+ assertEquals((short)3, cellStyle.getIndention());
+ cellStyle.setIndention((short) 13);
+ assertEquals((short)13, cellXf.getAlignment().getIndent());
+ }
+
+ public void testGetSetAlignement() {
+ assertEquals(1, cellStyle.getAlignment());
+ cellStyle.setAlignment((short)2);
+ assertEquals(STHorizontalAlignment.LEFT, cellStyle.getAlignmentEnum());
+ cellStyle.setAlignementEnum(STHorizontalAlignment.JUSTIFY);
+ assertEquals((short)6, cellStyle.getAlignment());
+ }
+
+ public void testGetSetVerticalAlignment() {
+ assertEquals(1, cellStyle.getVerticalAlignment());
+ cellStyle.setVerticalAlignment((short)2);
+ assertEquals(STVerticalAlignment.CENTER, cellStyle.getVerticalAlignmentEnum());
+ cellStyle.setVerticalAlignmentEnum(STVerticalAlignment.JUSTIFY);
+ assertEquals((short)4, cellStyle.getVerticalAlignment());
+ }
}