You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by pa...@apache.org on 2008/04/05 18:19:57 UTC
svn commit: r645129 - in /poi/branches/ooxml/src/ooxml:
java/org/apache/poi/xssf/usermodel/
java/org/apache/poi/xssf/usermodel/extensions/
testcases/org/apache/poi/xssf/usermodel/
Author: paolo
Date: Sat Apr 5 09:19:56 2008
New Revision: 645129
URL: http://svn.apache.org/viewvc?rev=645129&view=rev
Log:
XSSFCellStyle alignment methods and others + tests
Modified:
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=645129&r1=645128&r2=645129&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sat Apr 5 09:19:56 2008
@@ -22,11 +22,17 @@
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 {
@@ -36,6 +42,7 @@
private XSSFCellBorder cellBorder;
private XSSFCellFill cellFill;
private XSSFFont font;
+ private XSSFCellAlignment cellAlignment;
/**
* Creates a Cell Style from the supplied parts
@@ -75,8 +82,11 @@
}
public short getAlignment() {
- // TODO Auto-generated method stub
- return 0;
+ return (short)getAlignmentEnum().intValue();
+ }
+
+ public STHorizontalAlignment.Enum getAlignmentEnum() {
+ return getCellAlignment().getHorizontal();
}
public short getBorderBottom() {
@@ -135,8 +145,7 @@
}
public Font getFont(Workbook parentWorkbook) {
- // TODO Auto-generated method stub
- return null;
+ return getFont();
}
public Font getFont() {
@@ -147,18 +156,15 @@
}
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() {
@@ -171,8 +177,7 @@
}
public boolean getLocked() {
- // TODO Auto-generated method stub
- return false;
+ return getCellProtection().getLocked();
}
public short getRightBorderColor() {
@@ -180,8 +185,7 @@
}
public short getRotation() {
- // TODO Auto-generated method stub
- return 0;
+ return (short) getCellAlignment().getTextRotation();
}
public short getTopBorderColor() {
@@ -189,18 +193,23 @@
}
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) {
@@ -253,13 +262,11 @@
}
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) {
@@ -268,8 +275,7 @@
}
public void setLocked(boolean locked) {
- // TODO Auto-generated method stub
-
+ getCellProtection().setLocked(locked);
}
public void setRightBorderColor(short color) {
@@ -288,8 +294,11 @@
}
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) {
@@ -326,7 +335,7 @@
return (int) cellStyleXf.getFillId();
}
- private Enum getBorderStyle(BorderSides side) {
+ private STBorderStyle.Enum getBorderStyle(BorderSides side) {
return getCellBorder().getBorderStyle(side);
}
@@ -339,6 +348,27 @@
return (int) cellXf.getFontId();
}
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();
}
}
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java?rev=645129&r1=645128&r2=645129&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java Sat Apr 5 09:19:56 2008
@@ -18,7 +18,7 @@
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 {
@@ -29,7 +29,21 @@
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();
}
@@ -43,5 +57,13 @@
public void setIndent(long indent) {
cellAlignement.setIndent(indent);
+ }
+
+ public long getTextRotation() {
+ return cellAlignement.getTextRotation();
+ }
+
+ public boolean getWrapText() {
+ return cellAlignement.getWrapText();
}
}
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java?rev=645129&r1=645128&r2=645129&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java Sat Apr 5 09:19:56 2008
@@ -53,7 +53,7 @@
return borders.size() - 1;
}
- public Enum getBorderStyle(BorderSides side) {
+ public org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum getBorderStyle(BorderSides side) {
return getBorder(side).getStyle();
}
Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=645129&r1=645128&r2=645129&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java Sat Apr 5 09:19:56 2008
@@ -23,6 +23,7 @@
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;
@@ -30,7 +31,9 @@
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 {
@@ -41,12 +44,14 @@
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();
@@ -69,7 +74,8 @@
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);
}
@@ -136,5 +142,45 @@
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());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org