Lines 18-23
Link Here
|
18 |
|
18 |
|
19 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
20 |
import java.util.Collections; |
20 |
import java.util.Collections; |
|
|
21 |
import java.util.EnumMap; |
22 |
import java.util.HashMap; |
21 |
import java.util.List; |
23 |
import java.util.List; |
22 |
|
24 |
|
23 |
import org.apache.poi.POIXMLDocumentPart; |
25 |
import org.apache.poi.POIXMLDocumentPart; |
Lines 26-35
Link Here
|
26 |
import org.apache.xmlbeans.XmlObject; |
28 |
import org.apache.xmlbeans.XmlObject; |
27 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; |
29 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; |
28 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; |
30 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; |
|
|
31 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd; |
29 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; |
32 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; |
30 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; |
33 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; |
|
|
34 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr; |
35 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc; |
36 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd; |
37 |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc; |
31 |
|
38 |
|
32 |
|
39 |
/** |
|
|
40 |
* XWPFTableCell class. |
41 |
* |
42 |
* @author Gregg Morris (gregg dot morris at gmail dot com) - added XWPFVertAlign enum, |
43 |
* setColor(), |
44 |
* setVerticalAlignment() |
45 |
*/ |
33 |
public class XWPFTableCell implements IBody { |
46 |
public class XWPFTableCell implements IBody { |
34 |
private final CTTc ctTc; |
47 |
private final CTTc ctTc; |
35 |
protected List<XWPFParagraph> paragraphs = null; |
48 |
protected List<XWPFParagraph> paragraphs = null; |
Lines 37-42
Link Here
|
37 |
protected List<IBodyElement> bodyElements = null; |
50 |
protected List<IBodyElement> bodyElements = null; |
38 |
protected IBody part; |
51 |
protected IBody part; |
39 |
private XWPFTableRow tableRow = null; |
52 |
private XWPFTableRow tableRow = null; |
|
|
53 |
// Create a map from this XWPF-level enum to the STVerticalJc.Enum values |
54 |
public static enum XWPFVertAlign { TOP, CENTER, BOTH, BOTTOM }; |
55 |
private static EnumMap<XWPFVertAlign, STVerticalJc.Enum> alignMap; |
56 |
// Create a map from the STVerticalJc.Enum values to the XWPF-level enums |
57 |
private static HashMap<Integer, XWPFVertAlign> stVertAlignTypeMap; |
58 |
|
59 |
static { |
60 |
// populate enum maps |
61 |
alignMap = new EnumMap<XWPFVertAlign, STVerticalJc.Enum>(XWPFVertAlign.class); |
62 |
alignMap.put(XWPFVertAlign.TOP, STVerticalJc.Enum.forInt(STVerticalJc.INT_TOP)); |
63 |
alignMap.put(XWPFVertAlign.CENTER, STVerticalJc.Enum.forInt(STVerticalJc.INT_CENTER)); |
64 |
alignMap.put(XWPFVertAlign.BOTH, STVerticalJc.Enum.forInt(STVerticalJc.INT_BOTH)); |
65 |
alignMap.put(XWPFVertAlign.BOTTOM, STVerticalJc.Enum.forInt(STVerticalJc.INT_BOTTOM)); |
66 |
|
67 |
stVertAlignTypeMap = new HashMap<Integer, XWPFVertAlign>(); |
68 |
stVertAlignTypeMap.put(STVerticalJc.INT_TOP, XWPFVertAlign.TOP); |
69 |
stVertAlignTypeMap.put(STVerticalJc.INT_CENTER, XWPFVertAlign.CENTER); |
70 |
stVertAlignTypeMap.put(STVerticalJc.INT_BOTH, XWPFVertAlign.BOTH); |
71 |
stVertAlignTypeMap.put(STVerticalJc.INT_BOTTOM, XWPFVertAlign.BOTTOM); |
72 |
|
73 |
} |
74 |
|
40 |
/** |
75 |
/** |
41 |
* If a table cell does not include at least one block-level element, then this document shall be considered corrupt |
76 |
* If a table cell does not include at least one block-level element, then this document shall be considered corrupt |
42 |
*/ |
77 |
*/ |
Lines 152-157
Link Here
|
152 |
} |
187 |
} |
153 |
|
188 |
|
154 |
/** |
189 |
/** |
|
|
190 |
* Set cell color. This sets some associated values; for finer control |
191 |
* you may want to access these elements individually. |
192 |
* @param rgbStr - the desired cell color, in the hex form "RRGGBB". |
193 |
*/ |
194 |
public void setColor(String rgbStr) { |
195 |
CTTcPr tcpr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr(); |
196 |
CTShd ctshd = tcpr.isSetShd() ? tcpr.getShd() : tcpr.addNewShd(); |
197 |
ctshd.setColor("auto"); |
198 |
ctshd.setVal(STShd.CLEAR); |
199 |
ctshd.setFill(rgbStr); |
200 |
} |
201 |
|
202 |
/** |
203 |
* Get cell color. Note that this method only returns the "fill" value. |
204 |
* @return RGB string of cell color |
205 |
*/ |
206 |
public String getColor() { |
207 |
String color = null; |
208 |
CTTcPr tcpr = ctTc.getTcPr(); |
209 |
if (tcpr != null) { |
210 |
CTShd ctshd = tcpr.getShd(); |
211 |
if (ctshd != null) { |
212 |
color = ctshd.xgetFill().getStringValue(); |
213 |
} |
214 |
} |
215 |
return color; |
216 |
} |
217 |
|
218 |
/** |
219 |
* Set the vertical alignment of the cell. |
220 |
* @param vAlign - the desired alignment enum value |
221 |
*/ |
222 |
public void setVerticalAlignment(XWPFVertAlign vAlign) { |
223 |
CTTcPr tcpr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr(); |
224 |
CTVerticalJc va = tcpr.addNewVAlign(); |
225 |
va.setVal(alignMap.get(vAlign)); |
226 |
} |
227 |
|
228 |
/** |
229 |
* Get the vertical alignment of the cell. |
230 |
* @return the cell alignment enum value |
231 |
*/ |
232 |
public XWPFVertAlign getVerticalAlignment() { |
233 |
XWPFVertAlign vAlign = null; |
234 |
CTTcPr tcpr = ctTc.getTcPr(); |
235 |
if (ctTc != null) { |
236 |
CTVerticalJc va = tcpr.getVAlign(); |
237 |
vAlign = stVertAlignTypeMap.get(va.getVal().intValue()); |
238 |
} |
239 |
return vAlign; |
240 |
} |
241 |
|
242 |
/** |
155 |
* add a new paragraph at position of the cursor |
243 |
* add a new paragraph at position of the cursor |
156 |
* @param cursor |
244 |
* @param cursor |
157 |
* @return the inserted paragraph |
245 |
* @return the inserted paragraph |
Lines 346-352
Link Here
|
346 |
return null; |
434 |
return null; |
347 |
} |
435 |
} |
348 |
XWPFTableRow tableRow = table.getRow(row); |
436 |
XWPFTableRow tableRow = table.getRow(row); |
349 |
if(row == null){ |
437 |
if (tableRow == null) { |
350 |
return null; |
438 |
return null; |
351 |
} |
439 |
} |
352 |
return tableRow.getTableCell(cell); |
440 |
return tableRow.getTableCell(cell); |