Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

XWPFTable.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xwpf.usermodel;
  16. import java.math.BigInteger;
  17. import java.util.ArrayList;
  18. import java.util.EnumMap;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import org.apache.poi.POIXMLDocumentPart;
  22. import org.apache.poi.util.Internal;
  23. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
  24. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
  25. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
  26. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
  27. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
  28. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
  29. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
  30. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblCellMar;
  31. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
  32. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
  33. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
  34. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
  35. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
  36. /**
  37. * <p>Sketch of XWPFTable class. Only table's text is being hold.</p>
  38. * <p>Specifies the contents of a table present in the document. A table is a set
  39. * of paragraphs (and other block-level content) arranged in rows and columns.</p>
  40. */
  41. public class XWPFTable implements IBodyElement, ISDTContents {
  42. protected StringBuffer text = new StringBuffer();
  43. private CTTbl ctTbl;
  44. protected List<XWPFTableRow> tableRows;
  45. protected List<String> styleIDs;
  46. // Create a map from this XWPF-level enum to the STBorder.Enum values
  47. public static enum XWPFBorderType { NIL, NONE, SINGLE, THICK, DOUBLE, DOTTED, DASHED, DOT_DASH };
  48. private static EnumMap<XWPFBorderType, STBorder.Enum> xwpfBorderTypeMap;
  49. // Create a map from the STBorder.Enum values to the XWPF-level enums
  50. private static HashMap<Integer, XWPFBorderType> stBorderTypeMap;
  51. protected IBody part;
  52. static {
  53. // populate enum maps
  54. xwpfBorderTypeMap = new EnumMap<XWPFBorderType, STBorder.Enum>(XWPFBorderType.class);
  55. xwpfBorderTypeMap.put(XWPFBorderType.NIL, STBorder.Enum.forInt(STBorder.INT_NIL));
  56. xwpfBorderTypeMap.put(XWPFBorderType.NONE, STBorder.Enum.forInt(STBorder.INT_NONE));
  57. xwpfBorderTypeMap.put(XWPFBorderType.SINGLE, STBorder.Enum.forInt(STBorder.INT_SINGLE));
  58. xwpfBorderTypeMap.put(XWPFBorderType.THICK, STBorder.Enum.forInt(STBorder.INT_THICK));
  59. xwpfBorderTypeMap.put(XWPFBorderType.DOUBLE, STBorder.Enum.forInt(STBorder.INT_DOUBLE));
  60. xwpfBorderTypeMap.put(XWPFBorderType.DOTTED, STBorder.Enum.forInt(STBorder.INT_DOTTED));
  61. xwpfBorderTypeMap.put(XWPFBorderType.DASHED, STBorder.Enum.forInt(STBorder.INT_DASHED));
  62. xwpfBorderTypeMap.put(XWPFBorderType.DOT_DASH, STBorder.Enum.forInt(STBorder.INT_DOT_DASH));
  63. stBorderTypeMap = new HashMap<Integer, XWPFBorderType>();
  64. stBorderTypeMap.put(STBorder.INT_NIL, XWPFBorderType.NIL);
  65. stBorderTypeMap.put(STBorder.INT_NONE, XWPFBorderType.NONE);
  66. stBorderTypeMap.put(STBorder.INT_SINGLE, XWPFBorderType.SINGLE);
  67. stBorderTypeMap.put(STBorder.INT_THICK, XWPFBorderType.THICK);
  68. stBorderTypeMap.put(STBorder.INT_DOUBLE, XWPFBorderType.DOUBLE);
  69. stBorderTypeMap.put(STBorder.INT_DOTTED, XWPFBorderType.DOTTED);
  70. stBorderTypeMap.put(STBorder.INT_DASHED, XWPFBorderType.DASHED);
  71. stBorderTypeMap.put(STBorder.INT_DOT_DASH, XWPFBorderType.DOT_DASH);
  72. }
  73. public XWPFTable(CTTbl table, IBody part, int row, int col) {
  74. this(table, part);
  75. for (int i = 0; i < row; i++) {
  76. XWPFTableRow tabRow = (getRow(i) == null) ? createRow() : getRow(i);
  77. for (int k = 0; k < col; k++) {
  78. if (tabRow.getCell(k) == null) {
  79. tabRow.createCell();
  80. }
  81. }
  82. }
  83. }
  84. @SuppressWarnings("deprecation")
  85. public XWPFTable(CTTbl table, IBody part){
  86. this.part = part;
  87. this.ctTbl = table;
  88. tableRows = new ArrayList<XWPFTableRow>();
  89. // is an empty table: I add one row and one column as default
  90. if (table.sizeOfTrArray() == 0)
  91. createEmptyTable(table);
  92. for (CTRow row : table.getTrArray()) {
  93. StringBuilder rowText = new StringBuilder();
  94. XWPFTableRow tabRow = new XWPFTableRow(row, this);
  95. tableRows.add(tabRow);
  96. for (CTTc cell : row.getTcArray()) {
  97. for (CTP ctp : cell.getPArray()) {
  98. XWPFParagraph p = new XWPFParagraph(ctp, part);
  99. if (rowText.length() > 0) {
  100. rowText.append('\t');
  101. }
  102. rowText.append(p.getText());
  103. }
  104. }
  105. if (rowText.length() > 0) {
  106. this.text.append(rowText);
  107. this.text.append('\n');
  108. }
  109. }
  110. }
  111. private void createEmptyTable(CTTbl table) {
  112. // MINIMUM ELEMENTS FOR A TABLE
  113. table.addNewTr().addNewTc().addNewP();
  114. CTTblPr tblpro = table.addNewTblPr();
  115. tblpro.addNewTblW().setW(new BigInteger("0"));
  116. tblpro.getTblW().setType(STTblWidth.AUTO);
  117. // layout
  118. // tblpro.addNewTblLayout().setType(STTblLayoutType.AUTOFIT);
  119. // borders
  120. CTTblBorders borders = tblpro.addNewTblBorders();
  121. borders.addNewBottom().setVal(STBorder.SINGLE);
  122. borders.addNewInsideH().setVal(STBorder.SINGLE);
  123. borders.addNewInsideV().setVal(STBorder.SINGLE);
  124. borders.addNewLeft().setVal(STBorder.SINGLE);
  125. borders.addNewRight().setVal(STBorder.SINGLE);
  126. borders.addNewTop().setVal(STBorder.SINGLE);
  127. /*
  128. * CTTblGrid tblgrid=table.addNewTblGrid();
  129. * tblgrid.addNewGridCol().setW(new BigInteger("2000"));
  130. */
  131. getRows();
  132. }
  133. /**
  134. * @return ctTbl object
  135. */
  136. @Internal
  137. public CTTbl getCTTbl() {
  138. return ctTbl;
  139. }
  140. /**
  141. * Convenience method to extract text in cells. This
  142. * does not extract text recursively in cells, and it does not
  143. * currently include text in SDT (form) components.
  144. * <p>
  145. * To get all text within a table, see XWPFWordExtractor's appendTableText
  146. * as an example.
  147. *
  148. * @return text
  149. */
  150. public String getText() {
  151. return text.toString();
  152. }
  153. public void addNewRowBetween(int start, int end) {
  154. // TODO
  155. }
  156. /**
  157. * add a new column for each row in this table
  158. */
  159. public void addNewCol() {
  160. if (ctTbl.sizeOfTrArray() == 0) {
  161. createRow();
  162. }
  163. for (int i = 0; i < ctTbl.sizeOfTrArray(); i++) {
  164. XWPFTableRow tabRow = new XWPFTableRow(ctTbl.getTrArray(i), this);
  165. tabRow.createCell();
  166. }
  167. }
  168. /**
  169. * create a new XWPFTableRow object with as many cells as the number of columns defined in that moment
  170. *
  171. * @return tableRow
  172. */
  173. public XWPFTableRow createRow() {
  174. int sizeCol = ctTbl.sizeOfTrArray() > 0 ? ctTbl.getTrArray(0)
  175. .sizeOfTcArray() : 0;
  176. XWPFTableRow tabRow = new XWPFTableRow(ctTbl.addNewTr(), this);
  177. addColumn(tabRow, sizeCol);
  178. tableRows.add(tabRow);
  179. return tabRow;
  180. }
  181. /**
  182. * @param pos - index of the row
  183. * @return the row at the position specified or null if no rows is defined or if the position is greather than the max size of rows array
  184. */
  185. public XWPFTableRow getRow(int pos) {
  186. if (pos >= 0 && pos < ctTbl.sizeOfTrArray()) {
  187. //return new XWPFTableRow(ctTbl.getTrArray(pos));
  188. return getRows().get(pos);
  189. }
  190. return null;
  191. }
  192. /**
  193. * @param width
  194. */
  195. public void setWidth(int width) {
  196. CTTblPr tblPr = getTrPr();
  197. CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW();
  198. tblWidth.setW(new BigInteger("" + width));
  199. }
  200. /**
  201. * @return width value
  202. */
  203. public int getWidth() {
  204. CTTblPr tblPr = getTrPr();
  205. return tblPr.isSetTblW() ? tblPr.getTblW().getW().intValue() : -1;
  206. }
  207. /**
  208. * @return number of rows in table
  209. */
  210. public int getNumberOfRows() {
  211. return ctTbl.sizeOfTrArray();
  212. }
  213. private CTTblPr getTrPr() {
  214. return (ctTbl.getTblPr() != null) ? ctTbl.getTblPr() : ctTbl
  215. .addNewTblPr();
  216. }
  217. private void addColumn(XWPFTableRow tabRow, int sizeCol) {
  218. if (sizeCol > 0) {
  219. for (int i = 0; i < sizeCol; i++) {
  220. tabRow.createCell();
  221. }
  222. }
  223. }
  224. /**
  225. * get the StyleID of the table
  226. * @return style-ID of the table
  227. */
  228. public String getStyleID(){
  229. String styleId = null;
  230. CTTblPr tblPr = ctTbl.getTblPr();
  231. if (tblPr != null) {
  232. CTString styleStr = tblPr.getTblStyle();
  233. if (styleStr != null) {
  234. styleId = styleStr.getVal();
  235. }
  236. }
  237. return styleId;
  238. }
  239. /**
  240. * Set the table style. If the style is not defined in the document, MS Word
  241. * will set the table style to "Normal".
  242. * @param styleName - the style name to apply to this table
  243. */
  244. public void setStyleID(String styleName) {
  245. CTTblPr tblPr = getTrPr();
  246. CTString styleStr = tblPr.getTblStyle();
  247. if (styleStr == null) {
  248. styleStr = tblPr.addNewTblStyle();
  249. }
  250. styleStr.setVal(styleName);
  251. }
  252. public XWPFBorderType getInsideHBorderType() {
  253. XWPFBorderType bt = null;
  254. CTTblPr tblPr = getTrPr();
  255. if (tblPr.isSetTblBorders()) {
  256. CTTblBorders ctb = tblPr.getTblBorders();
  257. if (ctb.isSetInsideH()) {
  258. CTBorder border = ctb.getInsideH();
  259. bt = stBorderTypeMap.get(border.getVal().intValue());
  260. }
  261. }
  262. return bt;
  263. }
  264. public int getInsideHBorderSize() {
  265. int size = -1;
  266. CTTblPr tblPr = getTrPr();
  267. if (tblPr.isSetTblBorders()) {
  268. CTTblBorders ctb = tblPr.getTblBorders();
  269. if (ctb.isSetInsideH()) {
  270. CTBorder border = ctb.getInsideH();
  271. size = border.getSz().intValue();
  272. }
  273. }
  274. return size;
  275. }
  276. public int getInsideHBorderSpace() {
  277. int space = -1;
  278. CTTblPr tblPr = getTrPr();
  279. if (tblPr.isSetTblBorders()) {
  280. CTTblBorders ctb = tblPr.getTblBorders();
  281. if (ctb.isSetInsideH()) {
  282. CTBorder border = ctb.getInsideH();
  283. space = border.getSpace().intValue();
  284. }
  285. }
  286. return space;
  287. }
  288. public String getInsideHBorderColor() {
  289. String color = null;
  290. CTTblPr tblPr = getTrPr();
  291. if (tblPr.isSetTblBorders()) {
  292. CTTblBorders ctb = tblPr.getTblBorders();
  293. if (ctb.isSetInsideH()) {
  294. CTBorder border = ctb.getInsideH();
  295. color = border.xgetColor().getStringValue();
  296. }
  297. }
  298. return color;
  299. }
  300. public XWPFBorderType getInsideVBorderType() {
  301. XWPFBorderType bt = null;
  302. CTTblPr tblPr = getTrPr();
  303. if (tblPr.isSetTblBorders()) {
  304. CTTblBorders ctb = tblPr.getTblBorders();
  305. if (ctb.isSetInsideV()) {
  306. CTBorder border = ctb.getInsideV();
  307. bt = stBorderTypeMap.get(border.getVal().intValue());
  308. }
  309. }
  310. return bt;
  311. }
  312. public int getInsideVBorderSize() {
  313. int size = -1;
  314. CTTblPr tblPr = getTrPr();
  315. if (tblPr.isSetTblBorders()) {
  316. CTTblBorders ctb = tblPr.getTblBorders();
  317. if (ctb.isSetInsideV()) {
  318. CTBorder border = ctb.getInsideV();
  319. size = border.getSz().intValue();
  320. }
  321. }
  322. return size;
  323. }
  324. public int getInsideVBorderSpace() {
  325. int space = -1;
  326. CTTblPr tblPr = getTrPr();
  327. if (tblPr.isSetTblBorders()) {
  328. CTTblBorders ctb = tblPr.getTblBorders();
  329. if (ctb.isSetInsideV()) {
  330. CTBorder border = ctb.getInsideV();
  331. space = border.getSpace().intValue();
  332. }
  333. }
  334. return space;
  335. }
  336. public String getInsideVBorderColor() {
  337. String color = null;
  338. CTTblPr tblPr = getTrPr();
  339. if (tblPr.isSetTblBorders()) {
  340. CTTblBorders ctb = tblPr.getTblBorders();
  341. if (ctb.isSetInsideV()) {
  342. CTBorder border = ctb.getInsideV();
  343. color = border.xgetColor().getStringValue();
  344. }
  345. }
  346. return color;
  347. }
  348. public int getRowBandSize() {
  349. int size = 0;
  350. CTTblPr tblPr = getTrPr();
  351. if (tblPr.isSetTblStyleRowBandSize()) {
  352. CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize();
  353. size = rowSize.getVal().intValue();
  354. }
  355. return size;
  356. }
  357. public void setRowBandSize(int size) {
  358. CTTblPr tblPr = getTrPr();
  359. CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize();
  360. rowSize.setVal(BigInteger.valueOf(size));
  361. }
  362. public int getColBandSize() {
  363. int size = 0;
  364. CTTblPr tblPr = getTrPr();
  365. if (tblPr.isSetTblStyleColBandSize()) {
  366. CTDecimalNumber colSize = tblPr.getTblStyleColBandSize();
  367. size = colSize.getVal().intValue();
  368. }
  369. return size;
  370. }
  371. public void setColBandSize(int size) {
  372. CTTblPr tblPr = getTrPr();
  373. CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize();
  374. colSize.setVal(BigInteger.valueOf(size));
  375. }
  376. public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) {
  377. CTTblPr tblPr = getTrPr();
  378. CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
  379. CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH();
  380. b.setVal(xwpfBorderTypeMap.get(type));
  381. b.setSz(BigInteger.valueOf(size));
  382. b.setSpace(BigInteger.valueOf(space));
  383. b.setColor(rgbColor);
  384. }
  385. public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) {
  386. CTTblPr tblPr = getTrPr();
  387. CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
  388. CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV();
  389. b.setVal(xwpfBorderTypeMap.get(type));
  390. b.setSz(BigInteger.valueOf(size));
  391. b.setSpace(BigInteger.valueOf(space));
  392. b.setColor(rgbColor);
  393. }
  394. public int getCellMarginTop() {
  395. int margin = 0;
  396. CTTblPr tblPr = getTrPr();
  397. CTTblCellMar tcm = tblPr.getTblCellMar();
  398. if (tcm != null) {
  399. CTTblWidth tw = tcm.getTop();
  400. if (tw != null) {
  401. margin = tw.getW().intValue();
  402. }
  403. }
  404. return margin;
  405. }
  406. public int getCellMarginLeft() {
  407. int margin = 0;
  408. CTTblPr tblPr = getTrPr();
  409. CTTblCellMar tcm = tblPr.getTblCellMar();
  410. if (tcm != null) {
  411. CTTblWidth tw = tcm.getLeft();
  412. if (tw != null) {
  413. margin = tw.getW().intValue();
  414. }
  415. }
  416. return margin;
  417. }
  418. public int getCellMarginBottom() {
  419. int margin = 0;
  420. CTTblPr tblPr = getTrPr();
  421. CTTblCellMar tcm = tblPr.getTblCellMar();
  422. if (tcm != null) {
  423. CTTblWidth tw = tcm.getBottom();
  424. if (tw != null) {
  425. margin = tw.getW().intValue();
  426. }
  427. }
  428. return margin;
  429. }
  430. public int getCellMarginRight() {
  431. int margin = 0;
  432. CTTblPr tblPr = getTrPr();
  433. CTTblCellMar tcm = tblPr.getTblCellMar();
  434. if (tcm != null) {
  435. CTTblWidth tw = tcm.getRight();
  436. if (tw != null) {
  437. margin = tw.getW().intValue();
  438. }
  439. }
  440. return margin;
  441. }
  442. public void setCellMargins(int top, int left, int bottom, int right) {
  443. CTTblPr tblPr = getTrPr();
  444. CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
  445. CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft();
  446. tw.setType(STTblWidth.DXA);
  447. tw.setW(BigInteger.valueOf(left));
  448. tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop();
  449. tw.setType(STTblWidth.DXA);
  450. tw.setW(BigInteger.valueOf(top));
  451. tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom();
  452. tw.setType(STTblWidth.DXA);
  453. tw.setW(BigInteger.valueOf(bottom));
  454. tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight();
  455. tw.setType(STTblWidth.DXA);
  456. tw.setW(BigInteger.valueOf(right));
  457. }
  458. /**
  459. * add a new Row to the table
  460. *
  461. * @param row the row which should be added
  462. */
  463. public void addRow(XWPFTableRow row){
  464. ctTbl.addNewTr();
  465. ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
  466. tableRows.add(row);
  467. }
  468. /**
  469. * add a new Row to the table
  470. * at position pos
  471. * @param row the row which should be added
  472. */
  473. public boolean addRow(XWPFTableRow row, int pos){
  474. if(pos >= 0 && pos <= tableRows.size()){
  475. ctTbl.insertNewTr(pos);
  476. ctTbl.setTrArray(pos,row.getCtRow());
  477. tableRows.add(pos, row);
  478. return true;
  479. }
  480. return false;
  481. }
  482. /**
  483. * inserts a new tablerow
  484. * @param pos
  485. * @return the inserted row
  486. */
  487. public XWPFTableRow insertNewTableRow(int pos){
  488. if(pos >= 0 && pos <= tableRows.size()){
  489. CTRow row = ctTbl.insertNewTr(pos);
  490. XWPFTableRow tableRow = new XWPFTableRow(row, this);
  491. tableRows.add(pos, tableRow);
  492. return tableRow;
  493. }
  494. return null;
  495. }
  496. /**
  497. * Remove a row at position pos from the table
  498. * @param pos position the Row in the Table
  499. */
  500. public boolean removeRow(int pos) throws IndexOutOfBoundsException {
  501. if (pos >= 0 && pos < tableRows.size()) {
  502. if (ctTbl.sizeOfTrArray() > 0) {
  503. ctTbl.removeTr(pos);
  504. }
  505. tableRows.remove(pos);
  506. return true;
  507. }
  508. return false;
  509. }
  510. public List<XWPFTableRow> getRows() {
  511. return tableRows;
  512. }
  513. /**
  514. * returns the type of the BodyElement Table
  515. * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
  516. */
  517. public BodyElementType getElementType() {
  518. return BodyElementType.TABLE;
  519. }
  520. public IBody getBody() {
  521. return part;
  522. }
  523. /**
  524. * returns the part of the bodyElement
  525. * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
  526. */
  527. public POIXMLDocumentPart getPart() {
  528. if(part != null){
  529. return part.getPart();
  530. }
  531. return null;
  532. }
  533. /**
  534. * returns the partType of the bodyPart which owns the bodyElement
  535. * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
  536. */
  537. public BodyType getPartType() {
  538. return part.getPartType();
  539. }
  540. /**
  541. * returns the XWPFRow which belongs to the CTRow row
  542. * if this row is not existing in the table null will be returned
  543. */
  544. public XWPFTableRow getRow(CTRow row) {
  545. for(int i=0; i<getRows().size(); i++){
  546. if(getRows().get(i).getCtRow()== row) return getRow(i);
  547. }
  548. return null;
  549. }
  550. }