/**\r
* removes a paragraph of this tablecell\r
*\r
- * @param pos\r
+ * @param pos The position in the list of paragraphs, 0-based\r
*/\r
public void removeParagraph(int pos) {\r
paragraphs.remove(pos);\r
CTTcPr tcpr = ctTc.getTcPr();\r
if (tcpr != null) {\r
CTVerticalJc va = tcpr.getVAlign();\r
+ if(va != null) {\r
+ vAlign = stVertAlignTypeMap.get(va.getVal().intValue());\r
+ } else {\r
+ vAlign = XWPFVertAlign.TOP;\r
+ }\r
if (va != null && va.getVal() != null) {\r
vAlign = stVertAlignTypeMap.get(va.getVal().intValue());\r
}\r
/**\r
* add a new paragraph at position of the cursor\r
*\r
- * @param cursor\r
+ * @param cursor The XmlCursor structure created with XmlBeans\r
* @return the inserted paragraph\r
*/\r
public XWPFParagraph insertNewParagraph(final XmlCursor cursor) {\r
}\r
\r
public String getText() {\r
- StringBuffer text = new StringBuffer();\r
+ StringBuilder text = new StringBuilder();\r
for (XWPFParagraph p : paragraphs) {\r
text.append(p.getText());\r
}\r
\r
StringBuffer text = new StringBuffer();\r
for (int i = 0; i < bodyElements.size(); i++) {\r
- boolean isLast = (i == bodyElements.size() - 1) ? true : false;\r
+ boolean isLast = (i == bodyElements.size() - 1);\r
appendBodyElementText(text, bodyElements.get(i), isLast);\r
}\r
\r
private void appendBodyElementText(StringBuffer text, IBodyElement e, boolean isLast) {\r
if (e instanceof XWPFParagraph) {\r
text.append(((XWPFParagraph) e).getText());\r
- if (isLast == false) {\r
+ if (!isLast) {\r
text.append('\t');\r
}\r
} else if (e instanceof XWPFTable) {\r
for (XWPFTableCell cell : row.getTableCells()) {\r
List<IBodyElement> localBodyElements = cell.getBodyElements();\r
for (int i = 0; i < localBodyElements.size(); i++) {\r
- boolean localIsLast = (i == localBodyElements.size() - 1) ? true : false;\r
+ boolean localIsLast = (i == localBodyElements.size() - 1);\r
appendBodyElementText(text, localBodyElements.get(i), localIsLast);\r
}\r
}\r
}\r
\r
- if (isLast == false) {\r
+ if (!isLast) {\r
text.append('\n');\r
}\r
} else if (e instanceof XWPFSDT) {\r
text.append(((XWPFSDT) e).getContent().getText());\r
- if (isLast == false) {\r
+ if (!isLast) {\r
text.append('\t');\r
}\r
}\r
}\r
\r
// Create a map from this XWPF-level enum to the STVerticalJc.Enum values\r
- public static enum XWPFVertAlign {\r
+ public enum XWPFVertAlign {\r
TOP, CENTER, BOTH, BOTTOM\r
}\r
}\r
package org.apache.poi.xwpf.usermodel;
-import java.util.List;
-
import junit.framework.TestCase;
-
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+
+import java.util.List;
public class TestXWPFTableCell extends TestCase {
@Override
List<XWPFTableRow> tableRows = table.getRows();
assertEquals(2, tableRows.size());
- assertNull(tableRows.get(0).getCell(0).getVerticalAlignment());
+ assertEquals(XWPFVertAlign.TOP, tableRows.get(0).getCell(0).getVerticalAlignment());
assertEquals(XWPFVertAlign.BOTTOM, tableRows.get(0).getCell(1).getVerticalAlignment());
assertEquals(XWPFVertAlign.CENTER, tableRows.get(1).getCell(0).getVerticalAlignment());
- assertNull(tableRows.get(1).getCell(1).getVerticalAlignment());
+ assertEquals(XWPFVertAlign.TOP, tableRows.get(1).getCell(1).getVerticalAlignment());
}
+
+ public void testCellVerticalAlign2() throws Exception{
+ XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("TestTableCellAlign.docx");
+ List<XWPFTable> tables = docx.getTables();
+ for (XWPFTable table : tables) {
+ List<XWPFTableRow> tableRows = table.getRows();
+ for (XWPFTableRow tableRow : tableRows) {
+ List<XWPFTableCell> tableCells = tableRow.getTableCells();
+ for (XWPFTableCell tableCell : tableCells) {
+ assertNotNull(tableCell.getVerticalAlignment());
+ }
+ }
+ }
+ }
}