You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Row.java 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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.ss.usermodel;
  16. import java.util.Iterator;
  17. import java.util.Spliterator;
  18. import java.util.Spliterators;
  19. /**
  20. * High level representation of a row of a spreadsheet.
  21. */
  22. public interface Row extends Iterable<Cell> {
  23. /**
  24. * Use this to create new cells within the row and return it.
  25. * <p>
  26. * The cell that is returned is a {@link CellType#BLANK}. The type can be changed
  27. * either through calling <code>setCellValue</code> or <code>setCellType</code>.
  28. *
  29. * @param column - the column number this cell represents
  30. * @return Cell a high level representation of the created cell.
  31. * @throws IllegalArgumentException if columnIndex &lt; 0 or greater than the maximum number of supported columns
  32. * (255 for *.xls, 1048576 for *.xlsx)
  33. */
  34. Cell createCell(int column);
  35. /**
  36. * Use this to create new cells within the row and return it.
  37. * <p>
  38. * The cell that is returned will be of the requested type.
  39. * The type can be changed either through calling setCellValue
  40. * or setCellType, but there is a small overhead to doing this,
  41. * so it is best to create of the required type up front.
  42. *
  43. * @param column - the column number this cell represents
  44. * @param type - the cell's data type
  45. * @return Cell a high level representation of the created cell.
  46. * @throws IllegalArgumentException if columnIndex &lt; 0 or greater than a maximum number of supported columns
  47. * (255 for *.xls, 1048576 for *.xlsx)
  48. */
  49. Cell createCell(int column, CellType type);
  50. /**
  51. * Remove the Cell from this row.
  52. *
  53. * @param cell the cell to remove
  54. */
  55. void removeCell(Cell cell);
  56. /**
  57. * Set the row number of this row.
  58. *
  59. * @param rowNum the row number (0-based)
  60. * @throws IllegalArgumentException if rowNum &lt; 0
  61. */
  62. void setRowNum(int rowNum);
  63. /**
  64. * Get row number this row represents
  65. *
  66. * @return the row number (0 based)
  67. */
  68. int getRowNum();
  69. /**
  70. * Get the cell representing a given column (logical cell) 0-based. If you
  71. * ask for a cell that is not defined....you get a null.
  72. *
  73. * @param cellnum 0 based column number
  74. * @return Cell representing that column or null if undefined.
  75. * @see #getCell(int, org.apache.poi.ss.usermodel.Row.MissingCellPolicy)
  76. */
  77. Cell getCell(int cellnum);
  78. /**
  79. * Returns the cell at the given (0 based) index, with the specified {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy}
  80. *
  81. * @return the cell at the given (0 based) index
  82. * @throws IllegalArgumentException if cellnum &lt; 0 or the specified MissingCellPolicy is invalid
  83. */
  84. Cell getCell(int cellnum, MissingCellPolicy policy);
  85. /**
  86. * Get the number of the first cell contained in this row.
  87. *
  88. * Note: cells which had content before and were set to empty later might
  89. * still be counted as cells by Excel and Apache POI, so the result of this
  90. * method will include such rows and thus the returned value might be lower
  91. * than expected!
  92. *
  93. * @return short representing the first logical cell in the row,
  94. * or -1 if the row does not contain any cells.
  95. */
  96. short getFirstCellNum();
  97. /**
  98. * Gets the index of the last cell contained in this row <b>PLUS ONE</b>. The result also
  99. * happens to be the 1-based column number of the last cell. This value can be used as a
  100. * standard upper bound when iterating over cells:
  101. * <pre>
  102. * short minColIx = row.getFirstCellNum();
  103. * short maxColIx = row.getLastCellNum();
  104. * for(short colIx=minColIx; colIx&lt;maxColIx; colIx++) {
  105. * Cell cell = row.getCell(colIx);
  106. * if(cell == null) {
  107. * continue;
  108. * }
  109. * //... do something with cell
  110. * }
  111. * </pre>
  112. *
  113. * Note: cells which had content before and were set to empty later might
  114. * still be counted as cells by Excel and Apache POI, so the result of this
  115. * method will include such rows and thus the returned value might be higher
  116. * than expected!
  117. *
  118. * @return short representing the last logical cell in the row <b>PLUS ONE</b>,
  119. * or -1 if the row does not contain any cells.
  120. */
  121. short getLastCellNum();
  122. /**
  123. * Gets the number of defined cells (NOT number of cells in the actual row!).
  124. * That is to say if only columns 0,4,5 have values then there would be 3.
  125. *
  126. * @return int representing the number of defined cells in the row.
  127. */
  128. int getPhysicalNumberOfCells();
  129. /**
  130. * Set the row's height or set to ff (-1) for undefined/default-height. Set the height in "twips" or
  131. * 1/20th of a point.
  132. *
  133. * @param height rowheight or 0xff for undefined (use sheet default)
  134. */
  135. void setHeight(short height);
  136. /**
  137. * Set whether or not to display this row with 0 height
  138. *
  139. * @param zHeight height is zero or not.
  140. */
  141. void setZeroHeight(boolean zHeight);
  142. /**
  143. * Get whether or not to display this row with 0 height
  144. *
  145. * @return - zHeight height is zero or not.
  146. */
  147. boolean getZeroHeight();
  148. /**
  149. * Set the row's height in points.
  150. *
  151. * @param height the height in points. <code>-1</code> resets to the default height
  152. */
  153. void setHeightInPoints(float height);
  154. /**
  155. * Get the row's height measured in twips (1/20th of a point). If the height is not set, the default worksheet value is returned,
  156. * See {@link Sheet#getDefaultRowHeightInPoints()}
  157. *
  158. * @return row height measured in twips (1/20th of a point)
  159. */
  160. short getHeight();
  161. /**
  162. * Returns row height measured in point size. If the height is not set, the default worksheet value is returned,
  163. * See {@link Sheet#getDefaultRowHeightInPoints()}
  164. *
  165. * @return row height measured in point size
  166. * @see Sheet#getDefaultRowHeightInPoints()
  167. */
  168. float getHeightInPoints();
  169. /**
  170. * Is this row formatted? Most aren't, but some rows
  171. * do have whole-row styles. For those that do, you
  172. * can get the formatting from {@link #getRowStyle()}
  173. */
  174. boolean isFormatted();
  175. /**
  176. * Returns the whole-row cell styles. Most rows won't
  177. * have one of these, so will return null. Call
  178. * {@link #isFormatted()} to check first.
  179. */
  180. CellStyle getRowStyle();
  181. /**
  182. * Applies a whole-row cell styling to the row.
  183. */
  184. void setRowStyle(CellStyle style);
  185. /**
  186. * @return Cell iterator of the physically defined cells. Note element 4 may
  187. * actually be row cell depending on how many are defined!
  188. */
  189. Iterator<Cell> cellIterator();
  190. /**
  191. * Alias for {@link #cellIterator()} to allow foreach loops:
  192. * <blockquote><pre>
  193. * for(Cell cell : row){
  194. * ...
  195. * }
  196. * </pre></blockquote>
  197. *
  198. * @return an iterator over cells in this row.
  199. */
  200. @Override
  201. default Iterator<Cell> iterator() {
  202. return cellIterator();
  203. }
  204. /**
  205. * @return Cell spliterator of the physically defined cells. Note element 4 may
  206. * actually be row cell depending on how many are defined!
  207. *
  208. * @since POI 5.2.0
  209. */
  210. @Override
  211. default Spliterator<Cell> spliterator() {
  212. return Spliterators.spliterator(cellIterator(), getPhysicalNumberOfCells(), 0);
  213. }
  214. /**
  215. * Returns the Sheet this row belongs to
  216. *
  217. * @return the Sheet that owns this row
  218. */
  219. Sheet getSheet();
  220. /**
  221. * Used to specify the different possible policies
  222. * if for the case of null and blank cells
  223. */
  224. public enum MissingCellPolicy {
  225. RETURN_NULL_AND_BLANK,
  226. RETURN_BLANK_AS_NULL,
  227. CREATE_NULL_AS_BLANK
  228. }
  229. /**
  230. * Returns the rows outline level. Increased as you
  231. * put it into more groups (outlines), reduced as
  232. * you take it out of them.
  233. */
  234. public int getOutlineLevel();
  235. public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step);
  236. public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step);
  237. }