mirror of https://github.com/apache/poi.git
POI 59030 fix NPE in XWPFTableCell's getVerticalAlignment via Prasad Babu
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1731257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
36ae29751d
commit
12ac00eafd
|
@ -224,20 +224,23 @@ public class XWPFTableCell implements IBody, ICell {
|
|||
ctshd.setFill(rgbStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vertical alignment of the cell.
|
||||
*
|
||||
* @return the cell alignment enum value
|
||||
*/
|
||||
public XWPFVertAlign getVerticalAlignment() {
|
||||
XWPFVertAlign vAlign = null;
|
||||
CTTcPr tcpr = ctTc.getTcPr();
|
||||
if (tcpr != null) {
|
||||
CTVerticalJc va = tcpr.getVAlign();
|
||||
vAlign = stVertAlignTypeMap.get(va.getVal().intValue());
|
||||
}
|
||||
return vAlign;
|
||||
}
|
||||
/**
|
||||
* Get the vertical alignment of the cell.
|
||||
*
|
||||
* @return the cell alignment enum value or <code>null</code>
|
||||
* if no vertical alignment is set.
|
||||
*/
|
||||
public XWPFVertAlign getVerticalAlignment() {
|
||||
XWPFVertAlign vAlign = null;
|
||||
CTTcPr tcpr = ctTc.getTcPr();
|
||||
if (tcpr != null) {
|
||||
CTVerticalJc va = tcpr.getVAlign();
|
||||
if (va != null && va.getVal() != null) {
|
||||
vAlign = stVertAlignTypeMap.get(va.getVal().intValue());
|
||||
}
|
||||
}
|
||||
return vAlign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the vertical alignment of the cell.
|
||||
|
|
|
@ -19,8 +19,11 @@
|
|||
|
||||
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;
|
||||
|
@ -103,4 +106,20 @@ public class TestXWPFTableCell extends TestCase {
|
|||
CTTcBorders tblBorders = tcPr.addNewTcBorders();
|
||||
CTVMerge vMerge = tcPr.addNewVMerge();
|
||||
}
|
||||
|
||||
public void testCellVerticalAlign() throws Exception{
|
||||
XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("59030.docx");
|
||||
List<XWPFTable> tables = docx.getTables();
|
||||
assertEquals(1, tables.size());
|
||||
|
||||
XWPFTable table = tables.get(0);
|
||||
|
||||
List<XWPFTableRow> tableRows = table.getRows();
|
||||
assertEquals(2, tableRows.size());
|
||||
|
||||
assertNull(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());
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue