<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta1" date="2008-??-??">
- <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</actions>
+ <action dev="POI-DEVELOPERS" type="add">Add accessors to horizontal and vertical alignment in HSSFTextbox</action>
+ <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</action>
<action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
<action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
<action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta1" date="2008-??-??">
- <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</actions>
+ <action dev="POI-DEVELOPERS" type="add">Add accessors to horizontal and vertical alignment in HSSFTextbox</action>
+ <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</action>
<action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
<action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
<action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
HSSFTextbox shape = hssfShape;
TextObjectRecord obj = new TextObjectRecord();
- obj.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
- obj.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
+ obj.setHorizontalTextAlignment( hssfShape.getHorizontalAlignment() );
+ obj.setVerticalTextAlignment( hssfShape.getVerticalAlignment());
obj.setTextLocked( true );
obj.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
int frLength = ( shape.getString().numFormattingRuns() + 1 ) * 8;
package org.apache.poi.hssf.usermodel;
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+
/**
* A textbox is a shape that may hold a rich text string.
*
{
public final static short OBJECT_TYPE_TEXT = 6;
+ /**
+ * How to align text horizontally
+ */
+ public final static short HORIZONTAL_ALIGNMENT_LEFT = 1;
+ public final static short HORIZONTAL_ALIGNMENT_CENTERED = 2;
+ public final static short HORIZONTAL_ALIGNMENT_RIGHT = 3;
+ public final static short HORIZONTAL_ALIGNMENT_JUSTIFIED = 4;
+
+ /**
+ * How to align text vertically
+ */
+ public final static short VERTICAL_ALIGNMENT_TOP = 1;
+ public final static short VERTICAL_ALIGNMENT_CENTER = 2;
+ public final static short VERTICAL_ALIGNMENT_BOTTOM = 3;
+ public final static short VERTICAL_ALIGNMENT_JUSTIFY = 4;
+
+
int marginLeft, marginRight, marginTop, marginBottom;
+ short halign, valign;
HSSFRichTextString string = new HSSFRichTextString("");
{
super( parent, anchor );
setShapeType(OBJECT_TYPE_TEXT);
+
+ halign = HORIZONTAL_ALIGNMENT_LEFT;
+ valign = VERTICAL_ALIGNMENT_TOP;
}
/**
{
this.marginBottom = marginBottom;
}
+
+ /**
+ * Gets the horizontal alignment.
+ */
+ public short getHorizontalAlignment()
+ {
+ return halign;
+ }
+
+ /**
+ * Sets the horizontal alignment.
+ */
+ public void setHorizontalAlignment( short align )
+ {
+ this.halign = align;
+ }
+
+ /**
+ * Gets the vertical alignment.
+ */
+ public short getVerticalAlignment()
+ {
+ return valign;
+ }
+
+ /**
+ * Sets the vertical alignment.
+ */
+ public void setVerticalAlignment( short align )
+ {
+ this.valign = align;
+ }
}
--- /dev/null
+/*\r
+* Licensed to the Apache Software Foundation (ASF) under one or more\r
+* contributor license agreements. See the NOTICE file distributed with\r
+* this work for additional information regarding copyright ownership.\r
+* The ASF licenses this file to You under the Apache License, Version 2.0\r
+* (the "License"); you may not use this file except in compliance with\r
+* the License. You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+package org.apache.poi.hssf.usermodel;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+import junit.framework.TestCase;\r
+\r
+/**\r
+ * Test <code>HSSFTextbox</code>.\r
+ *\r
+ * @author Yegor Kozlov (yegor at apache.org)\r
+ */\r
+public final class TestHSSFTextbox extends TestCase{\r
+\r
+ /**\r
+ * Test that accessors to horizontal and vertical alignment work properly\r
+ */\r
+ public void testAlignment() {\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sh1 = wb.createSheet();\r
+ HSSFPatriarch patriarch = sh1.createDrawingPatriarch();\r
+\r
+ HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 6, 4));\r
+ HSSFRichTextString str = new HSSFRichTextString("Hello, World");\r
+ textbox.setString(str);\r
+ textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);\r
+ textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER);\r
+\r
+ assertEquals(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.getHorizontalAlignment());\r
+ assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment());\r
+ }\r
+\r
+ }\r