From bd09f7104319b1822100e3499cca0d353e5212fd Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Tue, 21 Feb 2012 12:39:23 +0000 Subject: [PATCH] Bugzilla 52701: fixed seting vertical alignment for XSLFTableCell git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1291743 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/xslf/usermodel/XSLFTableCell.java | 28 +++++++++++++++++++ .../poi/xslf/usermodel/TestXSLFTable.java | 6 ++++ 3 files changed, 35 insertions(+) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 85064486b6..9e88c81f2f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52701 - fixed seting vertical alignment for XSLFTableCell 52687 - fixed merging slides with pictures with associated custom tags allow runtime registration of functions in FormulaEvaluator 52665 - When reading from a ZipFileZipEntrySource that has already been closed, give IllegalArgumentException rather than NPE diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java index df63212af6..a3671ab63d 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java @@ -36,6 +36,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType; import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth; import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment; import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal; +import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType; /** * Represents a cell of a table in a .pptx presentation @@ -299,4 +300,31 @@ public class XSLFTableCell extends XSLFTextShape { void setVMerge(boolean merge_) { getXmlObject().setVMerge(merge_); } + + @Override + public void setVerticalAlignment(VerticalAlignment anchor){ + CTTableCellProperties cellProps = getXmlObject().getTcPr(); + if(cellProps != null) { + if(anchor == null) { + if(cellProps.isSetAnchor()) { + cellProps.unsetAnchor(); + } + } else { + cellProps.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1)); + } + } + } + + @Override + public VerticalAlignment getVerticalAlignment(){ + CTTableCellProperties cellProps = getXmlObject().getTcPr(); + + VerticalAlignment align = VerticalAlignment.TOP; + if(cellProps != null && cellProps.isSetAnchor()) { + int ival = cellProps.getAnchor().intValue(); + align = VerticalAlignment.values()[ival - 1]; + } + return align; + } + } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java index 9a4144752a..0ded02a5a7 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java @@ -142,5 +142,11 @@ public class TestXSLFTable extends TestCase { assertNull(cell1.getBorderRightColor()); cell1.setBorderRightColor(Color.yellow); assertEquals(Color.yellow, cell1.getBorderRightColor()); + + assertEquals(VerticalAlignment.TOP, cell1.getVerticalAlignment()); + cell1.setVerticalAlignment(VerticalAlignment.MIDDLE); + assertEquals(VerticalAlignment.MIDDLE, cell1.getVerticalAlignment()); + cell1.setVerticalAlignment(null); + assertEquals(VerticalAlignment.TOP, cell1.getVerticalAlignment()); } } \ No newline at end of file -- 2.39.5