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.

Sheet.java 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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.Collection;
  17. import java.util.Iterator;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Spliterator;
  21. import java.util.Spliterators;
  22. import org.apache.poi.ss.util.CellAddress;
  23. import org.apache.poi.ss.util.CellRangeAddress;
  24. import org.apache.poi.ss.util.PaneInformation;
  25. /**
  26. * High level representation of a Excel worksheet.
  27. *
  28. * <p>
  29. * Sheets are the central structures within a workbook, and are where a user does most of his spreadsheet work.
  30. * The most common type of sheet is the worksheet, which is represented as a grid of cells. Worksheet cells can
  31. * contain text, numbers, dates, and formulas. Cells can also be formatted.
  32. * </p>
  33. */
  34. public interface Sheet extends Iterable<Row> {
  35. /* Constants for margins */
  36. short LeftMargin = 0;
  37. short RightMargin = 1;
  38. short TopMargin = 2;
  39. short BottomMargin = 3;
  40. short HeaderMargin = 4;
  41. short FooterMargin = 5;
  42. byte PANE_LOWER_RIGHT = (byte) 0;
  43. byte PANE_UPPER_RIGHT = (byte) 1;
  44. byte PANE_LOWER_LEFT = (byte) 2;
  45. byte PANE_UPPER_LEFT = (byte) 3;
  46. /**
  47. * Create a new row within the sheet and return the high level representation
  48. *
  49. * @param rownum row number
  50. * @return high level Row object representing a row in the sheet
  51. * @see #removeRow(Row)
  52. */
  53. Row createRow(int rownum);
  54. /**
  55. * Remove a row from this sheet. All cells contained in the row are removed as well
  56. *
  57. * @param row representing a row to remove.
  58. */
  59. void removeRow(Row row);
  60. /**
  61. * Returns the logical row (not physical) 0-based. If you ask for a row that is not
  62. * defined you get a null. This is to say row 4 represents the fifth row on a sheet.
  63. *
  64. * @param rownum row to get (0-based)
  65. * @return Row representing the row-number or null if its not defined on the sheet
  66. */
  67. Row getRow(int rownum);
  68. /**
  69. * Returns the number of physically defined rows (NOT the number of rows in the sheet)
  70. *
  71. * @return the number of physically defined rows in this sheet
  72. */
  73. int getPhysicalNumberOfRows();
  74. /**
  75. * Gets the first row on the sheet.
  76. *
  77. * Note: rows which had content before and were set to empty later might
  78. * still be counted as rows by Excel and Apache POI, so the result of this
  79. * method will include such rows and thus the returned value might be lower
  80. * than expected!
  81. *
  82. * @return the number of the first logical row on the sheet (0-based)
  83. * or -1 if no row exists
  84. */
  85. int getFirstRowNum();
  86. /**
  87. * Gets the last row on the sheet
  88. *
  89. * Note: rows which had content before and were set to empty later might
  90. * still be counted as rows by Excel and Apache POI, so the result of this
  91. * method will include such rows and thus the returned value might be higher
  92. * than expected!
  93. *
  94. * @return last row contained on this sheet (0-based) or -1 if no row exists
  95. */
  96. int getLastRowNum();
  97. /**
  98. * Get the visibility state for a given column
  99. *
  100. * @param columnIndex - the column to get (0-based)
  101. * @param hidden - the visibility state of the column
  102. */
  103. void setColumnHidden(int columnIndex, boolean hidden);
  104. /**
  105. * Get the hidden state for a given column
  106. *
  107. * @param columnIndex - the column to set (0-based)
  108. * @return hidden - {@code false} if the column is visible
  109. */
  110. boolean isColumnHidden(int columnIndex);
  111. /**
  112. * Sets whether the worksheet is displayed from right to left instead of from left to right.
  113. *
  114. * @param value true for right to left, false otherwise.
  115. */
  116. void setRightToLeft(boolean value);
  117. /**
  118. * Whether the text is displayed in right-to-left mode in the window
  119. *
  120. * @return whether the text is displayed in right-to-left mode in the window
  121. */
  122. boolean isRightToLeft();
  123. /**
  124. * Set the width (in units of 1/256th of a character width)<p>
  125. *
  126. * The maximum column width for an individual cell is 255 characters.
  127. * This value represents the number of characters that can be displayed
  128. * in a cell that is formatted with the standard font (first font in the workbook).<p>
  129. *
  130. * Character width is defined as the maximum digit width
  131. * of the numbers {@code 0, 1, 2, ... 9} as rendered
  132. * using the default font (first font in the workbook).<p>
  133. *
  134. * Unless you are using a very special font, the default character is '0' (zero),
  135. * this is true for Arial (default font font in HSSF) and Calibri (default font in XSSF)<p>
  136. *
  137. * Please note, that the width set by this method includes 4 pixels of margin padding (two on each side),
  138. * plus 1 pixel padding for the gridlines (Section 3.3.1.12 of the OOXML spec).
  139. * This results is a slightly less value of visible characters than passed to this method (approx. 1/2 of a character).<p>
  140. *
  141. * To compute the actual number of visible characters,
  142. * Excel uses the following formula (Section 3.3.1.12 of the OOXML spec):<p>
  143. *
  144. * {@code
  145. * width = Truncate([{Number of Visible Characters} *
  146. * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256
  147. * }
  148. *
  149. * Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi).
  150. * If you set a column width to be eight characters wide, e.g. {@code setColumnWidth(columnIndex, 8*256)},
  151. * then the actual value of visible characters (the value shown in Excel) is derived from the following equation:
  152. * {@code
  153. * Truncate([numChars*7+5]/7*256)/256 = 8;
  154. * }
  155. *
  156. * which gives {@code 7.29}.
  157. *
  158. * @param columnIndex - the column to set (0-based)
  159. * @param width - the width in units of 1/256th of a character width
  160. * @throws IllegalArgumentException if width &gt; 255*256 (the maximum column width in Excel is 255 characters)
  161. */
  162. void setColumnWidth(int columnIndex, int width);
  163. /**
  164. * get the width (in units of 1/256th of a character width )
  165. *
  166. * <p>
  167. * Character width is defined as the maximum digit width
  168. * of the numbers {@code 0, 1, 2, ... 9} as rendered
  169. * using the default font (first font in the workbook)
  170. * </p>
  171. *
  172. * @param columnIndex - the column to get (0-based)
  173. * @return width - the width in units of 1/256th of a character width
  174. */
  175. int getColumnWidth(int columnIndex);
  176. /**
  177. * get the width in pixel
  178. *
  179. * <p>
  180. * Please note, that this method works correctly only for workbooks
  181. * with the default font size (Arial 10pt for .xls and Calibri 11pt for .xlsx).
  182. * If the default font is changed the column width can be stretched
  183. * </p>
  184. *
  185. * @param columnIndex - the column to set (0-based)
  186. * @return width in pixels
  187. */
  188. float getColumnWidthInPixels(int columnIndex);
  189. /**
  190. * Set the default column width for the sheet (if the columns do not define their own width)
  191. * in characters
  192. *
  193. * @param width default column width measured in characters
  194. */
  195. void setDefaultColumnWidth(int width);
  196. /**
  197. * Get the default column width for the sheet (if the columns do not define their own width)
  198. * in characters
  199. *
  200. * @return default column width measured in characters
  201. */
  202. int getDefaultColumnWidth();
  203. /**
  204. * Get the default row height for the sheet (if the rows do not define their own height) in
  205. * twips (1/20 of a point)
  206. *
  207. * @return default row height measured in twips (1/20 of a point)
  208. */
  209. short getDefaultRowHeight();
  210. /**
  211. * Get the default row height for the sheet (if the rows do not define their own height) in
  212. * points.
  213. *
  214. * @return default row height in points
  215. */
  216. float getDefaultRowHeightInPoints();
  217. /**
  218. * Set the default row height for the sheet (if the rows do not define their own height) in
  219. * twips (1/20 of a point)
  220. *
  221. * @param height default row height measured in twips (1/20 of a point)
  222. */
  223. void setDefaultRowHeight(short height);
  224. /**
  225. * Set the default row height for the sheet (if the rows do not define their own height) in
  226. * points
  227. * @param height default row height
  228. */
  229. void setDefaultRowHeightInPoints(float height);
  230. /**
  231. * Returns the CellStyle that applies to the given
  232. * (0 based) column, or null if no style has been
  233. * set for that column
  234. */
  235. CellStyle getColumnStyle(int column);
  236. /*
  237. * Sets the CellStyle that applies to the given
  238. * (0 based) column.
  239. */
  240. // public CellStyle setColumnStyle(int column, CellStyle style);
  241. /**
  242. * Adds a merged region of cells (hence those cells form one)
  243. *
  244. * @param region (rowfrom/colfrom-rowto/colto) to merge
  245. * @return index of this region
  246. */
  247. int addMergedRegion(CellRangeAddress region);
  248. /**
  249. * Adds a merged region of cells (hence those cells form one).
  250. * Skips validation. It is possible to create overlapping merged regions
  251. * or create a merged region that intersects a multi-cell array formula
  252. * with this formula, which may result in a corrupt workbook.
  253. *
  254. * To check for merged regions overlapping array formulas or other merged regions
  255. * after addMergedRegionUnsafe has been called, call {@link #validateMergedRegions()}, which runs in O(n^2) time.
  256. *
  257. * @param region to merge
  258. * @return index of this region
  259. * @throws IllegalArgumentException if region contains fewer than 2 cells
  260. */
  261. int addMergedRegionUnsafe(CellRangeAddress region);
  262. /**
  263. * Verify that merged regions do not intersect multi-cell array formulas and
  264. * no merged regions intersect another merged region in this sheet.
  265. *
  266. * @throws IllegalStateException if region intersects with a multi-cell array formula
  267. * @throws IllegalStateException if at least one region intersects with another merged region in this sheet
  268. */
  269. void validateMergedRegions();
  270. /**
  271. * Determines whether the output is vertically centered on the page.
  272. *
  273. * @param value true to vertically center, false otherwise.
  274. */
  275. void setVerticallyCenter(boolean value);
  276. /**
  277. * Determines whether the output is horizontally centered on the page.
  278. *
  279. * @param value true to horizontally center, false otherwise.
  280. */
  281. void setHorizontallyCenter(boolean value);
  282. /**
  283. * Determine whether printed output for this sheet will be horizontally centered.
  284. */
  285. boolean getHorizontallyCenter();
  286. /**
  287. * Determine whether printed output for this sheet will be vertically centered.
  288. */
  289. boolean getVerticallyCenter();
  290. /**
  291. * Removes a merged region of cells (hence letting them free)
  292. *
  293. * @param index of the region to unmerge
  294. */
  295. void removeMergedRegion(int index);
  296. /**
  297. * Removes a number of merged regions of cells (hence letting them free)
  298. *
  299. * @param indices A set of the regions to unmerge
  300. */
  301. void removeMergedRegions(Collection<Integer> indices);
  302. /**
  303. * Returns the number of merged regions
  304. *
  305. * @return number of merged regions
  306. */
  307. int getNumMergedRegions();
  308. /**
  309. * Returns the merged region at the specified index
  310. *
  311. * @return the merged region at the specified index
  312. */
  313. CellRangeAddress getMergedRegion(int index);
  314. /**
  315. * Returns the list of merged regions.
  316. *
  317. * @return the list of merged regions
  318. */
  319. List<CellRangeAddress> getMergedRegions();
  320. /**
  321. * Returns an iterator of the physical rows
  322. *
  323. * @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
  324. * be the third row if say for instance the second row is undefined.
  325. */
  326. Iterator<Row> rowIterator();
  327. /**
  328. * Alias for {@link #rowIterator()} to allow foreach loops
  329. */
  330. @Override
  331. default Iterator<Row> iterator() {
  332. return rowIterator();
  333. }
  334. /**
  335. * Returns a spliterator of the physical rows
  336. *
  337. * @return a spliterator of the PHYSICAL rows. Meaning the 3rd element may not
  338. * be the third row if say for instance the second row is undefined.
  339. *
  340. * @since POI 5.2.0
  341. */
  342. @Override
  343. default Spliterator<Row> spliterator() {
  344. return Spliterators.spliterator(rowIterator(), getPhysicalNumberOfRows(), 0);
  345. }
  346. /**
  347. * Control if Excel should be asked to recalculate all formulas on this sheet
  348. * when the workbook is opened.
  349. *
  350. * <p>
  351. * Calculating the formula values with {@link FormulaEvaluator} is the
  352. * recommended solution, but this may be used for certain cases where
  353. * evaluation in POI is not possible.
  354. * </p>
  355. *
  356. * To force recalculation of formulas in the entire workbook
  357. * use {@link Workbook#setForceFormulaRecalculation(boolean)} instead.
  358. *
  359. * @param value true if the application will perform a full recalculation of
  360. * this worksheet values when the workbook is opened
  361. *
  362. * @see Workbook#setForceFormulaRecalculation(boolean)
  363. */
  364. void setForceFormulaRecalculation(boolean value);
  365. /**
  366. * Whether Excel will be asked to recalculate all formulas in this sheet when the
  367. * workbook is opened.
  368. *
  369. * Note: This just returns if the sheet has the recalculate flag set and
  370. * will still return false even if recalculation is enabled on workbook-level.
  371. *
  372. * @return true if the Sheet has the recalculate-flag set.
  373. */
  374. boolean getForceFormulaRecalculation();
  375. /**
  376. * Flag indicating whether the sheet displays Automatic Page Breaks.
  377. *
  378. * @param value {@code true} if the sheet displays Automatic Page Breaks.
  379. */
  380. void setAutobreaks(boolean value);
  381. /**
  382. * Set whether to display the guts or not
  383. *
  384. * @param value - guts or no guts
  385. */
  386. void setDisplayGuts(boolean value);
  387. /**
  388. * Set whether the window should show 0 (zero) in cells containing zero value.
  389. * When false, cells with zero value appear blank instead of showing the number zero.
  390. *
  391. * @param value whether to display or hide all zero values on the worksheet
  392. */
  393. void setDisplayZeros(boolean value);
  394. /**
  395. * Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value.
  396. * When false, cells with zero value appear blank instead of showing the number zero.
  397. *
  398. * @return whether all zero values on the worksheet are displayed
  399. */
  400. boolean isDisplayZeros();
  401. /**
  402. * Flag indicating whether the Fit to Page print option is enabled.
  403. *
  404. * @param value {@code true} if the Fit to Page print option is enabled.
  405. */
  406. void setFitToPage(boolean value);
  407. /**
  408. * Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
  409. *
  410. * <p>
  411. * When true a summary row is inserted below the detailed data being summarized and a
  412. * new outline level is established on that row.
  413. * </p>
  414. * <p>
  415. * When false a summary row is inserted above the detailed data being summarized and a new outline level
  416. * is established on that row.
  417. * </p>
  418. * @param value {@code true} if row summaries appear below detail in the outline
  419. */
  420. void setRowSumsBelow(boolean value);
  421. /**
  422. * Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.
  423. *
  424. * <p>
  425. * When true a summary column is inserted to the right of the detailed data being summarized
  426. * and a new outline level is established on that column.
  427. * </p>
  428. * <p>
  429. * When false a summary column is inserted to the left of the detailed data being
  430. * summarized and a new outline level is established on that column.
  431. * </p>
  432. * @param value {@code true} if col summaries appear right of the detail in the outline
  433. */
  434. void setRowSumsRight(boolean value);
  435. /**
  436. * Flag indicating whether the sheet displays Automatic Page Breaks.
  437. *
  438. * @return {@code true} if the sheet displays Automatic Page Breaks.
  439. */
  440. boolean getAutobreaks();
  441. /**
  442. * Get whether to display the guts or not,
  443. * default value is true
  444. *
  445. * @return boolean - guts or no guts
  446. */
  447. boolean getDisplayGuts();
  448. /**
  449. * Flag indicating whether the Fit to Page print option is enabled.
  450. *
  451. * @return {@code true} if the Fit to Page print option is enabled.
  452. */
  453. boolean getFitToPage();
  454. /**
  455. * Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
  456. *
  457. * <p>
  458. * When true a summary row is inserted below the detailed data being summarized and a
  459. * new outline level is established on that row.
  460. * </p>
  461. * <p>
  462. * When false a summary row is inserted above the detailed data being summarized and a new outline level
  463. * is established on that row.
  464. * </p>
  465. * @return {@code true} if row summaries appear below detail in the outline
  466. */
  467. boolean getRowSumsBelow();
  468. /**
  469. * Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.
  470. *
  471. * <p>
  472. * When true a summary column is inserted to the right of the detailed data being summarized
  473. * and a new outline level is established on that column.
  474. * </p>
  475. * <p>
  476. * When false a summary column is inserted to the left of the detailed data being
  477. * summarized and a new outline level is established on that column.
  478. * </p>
  479. * @return {@code true} if col summaries appear right of the detail in the outline
  480. */
  481. boolean getRowSumsRight();
  482. /**
  483. * Gets the flag indicating whether this sheet displays the lines
  484. * between rows and columns to make editing and reading easier.
  485. *
  486. * @return {@code true} if this sheet prints gridlines.
  487. * @see #isDisplayGridlines() to check if gridlines are displayed on screen
  488. */
  489. boolean isPrintGridlines();
  490. /**
  491. * Sets the flag indicating whether this sheet should print the lines
  492. * between rows and columns to make editing and reading easier.
  493. *
  494. * @param show {@code true} if this sheet should print gridlines.
  495. * @see #setDisplayGridlines(boolean) to display gridlines on screen
  496. */
  497. void setPrintGridlines(boolean show);
  498. /**
  499. * Gets the flag indicating whether this sheet prints the
  500. * row and column headings when printing.
  501. *
  502. * @return {@code true} if this sheet prints row and column headings.
  503. */
  504. boolean isPrintRowAndColumnHeadings();
  505. /**
  506. * Sets the flag indicating whether this sheet should print
  507. * row and columns headings when printing.
  508. *
  509. * @param show {@code true} if this sheet should print row and column headings.
  510. */
  511. void setPrintRowAndColumnHeadings(boolean show);
  512. /**
  513. * Gets the print setup object.
  514. *
  515. * @return The user model for the print setup object.
  516. */
  517. PrintSetup getPrintSetup();
  518. /**
  519. * Gets the user model for the default document header.<p>
  520. *
  521. * Note that XSSF offers more kinds of document headers than HSSF does
  522. *
  523. * @return the document header. Never {@code null}
  524. */
  525. Header getHeader();
  526. /**
  527. * Gets the user model for the default document footer.<p>
  528. *
  529. * Note that XSSF offers more kinds of document footers than HSSF does.
  530. *
  531. * @return the document footer. Never {@code null}
  532. */
  533. Footer getFooter();
  534. /**
  535. * Sets a flag indicating whether this sheet is selected.<p>
  536. *
  537. * Note: multiple sheets can be selected, but only one sheet can be active at one time.
  538. *
  539. * @param value {@code true} if this sheet is selected
  540. * @see Workbook#setActiveSheet(int)
  541. */
  542. void setSelected(boolean value);
  543. /**
  544. * Gets the size of the margin in inches.
  545. *
  546. * @param margin which margin to get
  547. * @return the size of the margin
  548. */
  549. double getMargin(short margin);
  550. /**
  551. * Sets the size of the margin in inches.
  552. *
  553. * @param margin which margin to get
  554. * @param size the size of the margin
  555. */
  556. void setMargin(short margin, double size);
  557. /**
  558. * Answer whether protection is enabled or disabled
  559. *
  560. * @return true =&gt; protection enabled; false =&gt; protection disabled
  561. */
  562. boolean getProtect();
  563. /**
  564. * Sets the protection enabled as well as the password
  565. * @param password to set for protection. Pass {@code null} to remove protection
  566. */
  567. void protectSheet(String password);
  568. /**
  569. * Answer whether scenario protection is enabled or disabled
  570. *
  571. * @return true =&gt; protection enabled; false =&gt; protection disabled
  572. */
  573. boolean getScenarioProtect();
  574. /**
  575. * Window zoom magnification for current view representing percent values.
  576. * Valid values range from 10 to 400. Horizontal &amp; Vertical scale together.
  577. *
  578. * For example:
  579. * <pre>
  580. * 10 - 10%
  581. * 20 - 20%
  582. * ...
  583. * 100 - 100%
  584. * ...
  585. * 400 - 400%
  586. * </pre>
  587. *
  588. * @param scale window zoom magnification
  589. * @throws IllegalArgumentException if scale is invalid
  590. */
  591. void setZoom(int scale);
  592. /**
  593. * The top row in the visible view when the sheet is
  594. * first viewed after opening it in a viewer
  595. *
  596. * @return short indicating the rownum (0 based) of the top row
  597. */
  598. short getTopRow();
  599. /**
  600. * The left col in the visible view when the sheet is
  601. * first viewed after opening it in a viewer
  602. *
  603. * @return short indicating the rownum (0 based) of the top row
  604. */
  605. short getLeftCol();
  606. /**
  607. * Sets desktop window pane display area, when the
  608. * file is first opened in a viewer.
  609. *
  610. * @param topRow the top row to show in desktop window pane
  611. * @param leftCol the left column to show in desktop window pane
  612. */
  613. void showInPane(int topRow, int leftCol);
  614. /**
  615. * Shifts rows between startRow and endRow n number of rows.
  616. * If you use a negative number, it will shift rows up.
  617. * Code ensures that rows don't wrap around.
  618. *
  619. * Calls shiftRows(startRow, endRow, n, false, false);
  620. *
  621. * <p>
  622. * Additionally shifts merged regions that are completely defined in these
  623. * rows (ie. merged 2 cells on a row to be shifted).
  624. * @param startRow the row to start shifting
  625. * @param endRow the row to end shifting
  626. * @param n the number of rows to shift
  627. */
  628. void shiftRows(int startRow, int endRow, int n);
  629. /**
  630. * Shifts rows between startRow and endRow n number of rows.
  631. * If you use a negative number, it will shift rows up.
  632. * Code ensures that rows don't wrap around
  633. *
  634. * <p>
  635. * Additionally shifts merged regions that are completely defined in these
  636. * rows (ie. merged 2 cells on a row to be shifted). All merged regions that are
  637. * completely overlaid by shifting will be deleted.
  638. *
  639. * @param startRow the row to start shifting
  640. * @param endRow the row to end shifting
  641. * @param n the number of rows to shift
  642. * @param copyRowHeight whether to copy the row height during the shift
  643. * @param resetOriginalRowHeight whether to set the original row's height to the default
  644. */
  645. void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight);
  646. /**
  647. * Shifts columns between startColumn and endColumn, n number of columns.
  648. * If you use a negative number, it will shift columns left.
  649. * Code ensures that columns don't wrap around
  650. *
  651. * @param startColumn the column to start shifting
  652. * @param endColumn the column to end shifting
  653. * @param n the number of columns to shift
  654. */
  655. void shiftColumns(int startColumn, int endColumn, int n);
  656. /**
  657. * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
  658. * <p>
  659. * If both colSplit and rowSplit are zero then the existing freeze pane is removed
  660. * </p>
  661. * @param colSplit Horizontal position of split.
  662. * @param rowSplit Vertical position of split.
  663. * @param leftmostColumn Left column visible in right pane.
  664. * @param topRow Top row visible in bottom pane
  665. */
  666. void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow);
  667. /**
  668. * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
  669. * <p>
  670. * If both colSplit and rowSplit are zero then the existing freeze pane is removed
  671. * </p>
  672. * @param colSplit Horizontal position of split.
  673. * @param rowSplit Vertical position of split.
  674. */
  675. void createFreezePane(int colSplit, int rowSplit);
  676. /**
  677. * Creates a split pane. Any existing freezepane or split pane is overwritten.
  678. * @param xSplitPos Horizontal position of split (in 1/20th of a point).
  679. * @param ySplitPos Vertical position of split (in 1/20th of a point).
  680. * @param topRow Top row visible in bottom pane
  681. * @param leftmostColumn Left column visible in right pane.
  682. * @param activePane Active pane. One of: PANE_LOWER_RIGHT,
  683. * PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT
  684. * @see #PANE_LOWER_LEFT
  685. * @see #PANE_LOWER_RIGHT
  686. * @see #PANE_UPPER_LEFT
  687. * @see #PANE_UPPER_RIGHT
  688. */
  689. void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane);
  690. /**
  691. * Returns the information regarding the currently configured pane (split or freeze)
  692. *
  693. * @return null if no pane configured, or the pane information.
  694. */
  695. PaneInformation getPaneInformation();
  696. /**
  697. * Sets whether the gridlines are shown in a viewer
  698. *
  699. * @param show whether to show gridlines or not
  700. */
  701. void setDisplayGridlines(boolean show);
  702. /**
  703. * Returns if gridlines are displayed
  704. *
  705. * @return whether gridlines are displayed
  706. */
  707. boolean isDisplayGridlines();
  708. /**
  709. * Sets whether the formulas are shown in a viewer
  710. *
  711. * @param show whether to show formulas or not
  712. */
  713. void setDisplayFormulas(boolean show);
  714. /**
  715. * Returns if formulas are displayed
  716. *
  717. * @return whether formulas are displayed
  718. */
  719. boolean isDisplayFormulas();
  720. /**
  721. * Sets whether the RowColHeadings are shown in a viewer
  722. *
  723. * @param show whether to show RowColHeadings or not
  724. */
  725. void setDisplayRowColHeadings(boolean show);
  726. /**
  727. * Returns if RowColHeadings are displayed.
  728. * @return whether RowColHeadings are displayed
  729. */
  730. boolean isDisplayRowColHeadings();
  731. /**
  732. * Sets a page break at the indicated row
  733. * Breaks occur above the specified row and left of the specified column inclusive.
  734. *
  735. * For example, {@code sheet.setColumnBreak(2);} breaks the sheet into two parts
  736. * with columns A,B,C in the first and D,E,... in the second. Similar, {@code sheet.setRowBreak(2);}
  737. * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
  738. * and rows starting with rownum=4 in the second.
  739. *
  740. * @param row the row to break, inclusive
  741. */
  742. void setRowBreak(int row);
  743. /**
  744. * Determines if there is a page break at the indicated row
  745. * @param row FIXME: Document this!
  746. * @return FIXME: Document this!
  747. */
  748. boolean isRowBroken(int row);
  749. /**
  750. * Removes the page break at the indicated row
  751. * @param row The 0-based index of the row.
  752. */
  753. void removeRowBreak(int row);
  754. /**
  755. * Retrieves all the horizontal page breaks
  756. * @return all the horizontal page breaks, or null if there are no row page breaks
  757. */
  758. int[] getRowBreaks();
  759. /**
  760. * Retrieves all the vertical page breaks
  761. * @return all the vertical page breaks, or null if there are no column page breaks
  762. */
  763. int[] getColumnBreaks();
  764. /**
  765. * Sets a page break at the indicated column.
  766. * Breaks occur above the specified row and left of the specified column inclusive.
  767. *
  768. * For example, {@code sheet.setColumnBreak(2);} breaks the sheet into two parts
  769. * with columns A,B,C in the first and D,E,... in the second. Similar, {@code sheet.setRowBreak(2);}
  770. * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
  771. * and rows starting with rownum=4 in the second.
  772. *
  773. * @param column the column to break, inclusive
  774. */
  775. void setColumnBreak(int column);
  776. /**
  777. * Determines if there is a page break at the indicated column
  778. * @param column FIXME: Document this!
  779. * @return FIXME: Document this!
  780. */
  781. boolean isColumnBroken(int column);
  782. /**
  783. * Removes a page break at the indicated column
  784. * @param column The 0-based index of the column.
  785. */
  786. void removeColumnBreak(int column);
  787. /**
  788. * Expands or collapses a column group.
  789. *
  790. * @param columnNumber One of the columns in the group.
  791. * @param collapsed true = collapse group, false = expand group.
  792. */
  793. void setColumnGroupCollapsed(int columnNumber, boolean collapsed);
  794. /**
  795. * Create an outline for the provided column range.
  796. *
  797. * @param fromColumn beginning of the column range.
  798. * @param toColumn end of the column range.
  799. */
  800. void groupColumn(int fromColumn, int toColumn);
  801. /**
  802. * Ungroup a range of columns that were previously grouped
  803. *
  804. * @param fromColumn start column (0-based)
  805. * @param toColumn end column (0-based)
  806. */
  807. void ungroupColumn(int fromColumn, int toColumn);
  808. /**
  809. * Tie a range of rows together so that they can be collapsed or expanded
  810. *
  811. * @param fromRow start row (0-based)
  812. * @param toRow end row (0-based)
  813. */
  814. void groupRow(int fromRow, int toRow);
  815. /**
  816. * Ungroup a range of rows that were previously grouped
  817. *
  818. * @param fromRow start row (0-based)
  819. * @param toRow end row (0-based)
  820. */
  821. void ungroupRow(int fromRow, int toRow);
  822. /**
  823. * Set view state of a grouped range of rows
  824. *
  825. * @param row start row of a grouped range of rows (0-based)
  826. * @param collapse whether to expand/collapse the detail rows
  827. */
  828. void setRowGroupCollapsed(int row, boolean collapse);
  829. /**
  830. * Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
  831. *
  832. * @param column the column index
  833. * @param style the style to set
  834. */
  835. void setDefaultColumnStyle(int column, CellStyle style);
  836. /**
  837. * Adjusts the column width to fit the contents.
  838. *
  839. * <p>
  840. * This process can be relatively slow on large sheets, so this should
  841. * normally only be called once per column, at the end of your
  842. * processing.
  843. * </p>
  844. * You can specify whether the content of merged cells should be considered or ignored.
  845. * Default is to ignore merged cells.
  846. *
  847. * @param column the column index
  848. */
  849. void autoSizeColumn(int column);
  850. /**
  851. * Adjusts the column width to fit the contents.
  852. * <p>
  853. * This process can be relatively slow on large sheets, so this should
  854. * normally only be called once per column, at the end of your
  855. * processing.
  856. * </p>
  857. * You can specify whether the content of merged cells should be considered or ignored.
  858. * Default is to ignore merged cells.
  859. *
  860. * @param column the column index
  861. * @param useMergedCells whether to use the contents of merged cells when calculating the width of the column
  862. */
  863. void autoSizeColumn(int column, boolean useMergedCells);
  864. /**
  865. * Returns cell comment for the specified location
  866. *
  867. * @return cell comment or {@code null} if not found
  868. */
  869. Comment getCellComment(CellAddress ref);
  870. /**
  871. * Returns all cell comments on this sheet.
  872. * @return A map of each Comment in the sheet, keyed on the cell address where
  873. * the comment is located.
  874. */
  875. Map<CellAddress, ? extends Comment> getCellComments();
  876. /**
  877. * Return the sheet's existing drawing, or null if there isn't yet one.
  878. *
  879. * Use {@link #createDrawingPatriarch()} to get or create
  880. *
  881. * @return a SpreadsheetML drawing
  882. */
  883. Drawing<?> getDrawingPatriarch();
  884. /**
  885. * Creates the top-level drawing patriarch.
  886. * <p>This may then be used to add graphics or charts.</p>
  887. * <p>Note that this will normally have the effect of removing
  888. * any existing drawings on this sheet.</p>
  889. *
  890. * @return The new drawing patriarch.
  891. */
  892. Drawing<?> createDrawingPatriarch();
  893. /**
  894. * Return the parent workbook
  895. *
  896. * @return the parent workbook
  897. */
  898. Workbook getWorkbook();
  899. /**
  900. * Returns the name of this sheet
  901. *
  902. * @return the name of this sheet
  903. */
  904. String getSheetName();
  905. /**
  906. * Note - this is not the same as whether the sheet is focused (isActive)
  907. * @return {@code true} if this sheet is currently selected
  908. */
  909. boolean isSelected();
  910. /**
  911. * Sets array formula to specified region for result.
  912. * <p>
  913. * Note if there are shared formulas this will invalidate any
  914. * {@link FormulaEvaluator} instances based on this workbook
  915. *</p>
  916. * @param formula text representation of the formula
  917. * @param range Region of array formula for result.
  918. * @return the {@link CellRange} of cells affected by this change
  919. */
  920. CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress range);
  921. /**
  922. * Remove a Array Formula from this sheet. All cells contained in the Array Formula range are removed as well
  923. *
  924. * @param cell any cell within Array Formula range
  925. * @return the {@link CellRange} of cells affected by this change
  926. */
  927. CellRange<? extends Cell> removeArrayFormula(Cell cell);
  928. DataValidationHelper getDataValidationHelper();
  929. /**
  930. * Returns the list of DataValidation in the sheet.
  931. * @return list of DataValidation in the sheet
  932. */
  933. List<? extends DataValidation> getDataValidations();
  934. /**
  935. * Creates a data validation object
  936. * @param dataValidation The Data validation object settings
  937. */
  938. void addValidationData(DataValidation dataValidation);
  939. /**
  940. * Enable filtering for a range of cells
  941. *
  942. * @param range the range of cells to filter
  943. */
  944. AutoFilter setAutoFilter(CellRangeAddress range);
  945. /**
  946. * The 'Conditional Formatting' facet for this {@code Sheet}
  947. *
  948. * @return conditional formatting rule for this sheet
  949. */
  950. SheetConditionalFormatting getSheetConditionalFormatting();
  951. /**
  952. * Gets the repeating rows used when printing the sheet, as found in
  953. * File-&gt;PageSetup-&gt;Sheet.<p>
  954. *
  955. * Repeating rows cover a range of contiguous rows, e.g.:
  956. * <pre>
  957. * Sheet1!$1:$1
  958. * Sheet2!$5:$8
  959. * </pre>
  960. * The {@link CellRangeAddress} returned contains a column part which spans
  961. * all columns, and a row part which specifies the contiguous range of
  962. * repeating rows.<p>
  963. *
  964. * If the Sheet does not have any repeating rows defined, null is returned.
  965. *
  966. * @return an {@link CellRangeAddress} containing the repeating rows for the
  967. * Sheet, or null.
  968. */
  969. CellRangeAddress getRepeatingRows();
  970. /**
  971. * Gets the repeating columns used when printing the sheet, as found in
  972. * File-&gt;PageSetup-&gt;Sheet.<p>
  973. *
  974. * Repeating columns cover a range of contiguous columns, e.g.:
  975. * <pre>
  976. * Sheet1!$A:$A
  977. * Sheet2!$C:$F
  978. * </pre>
  979. * The {@link CellRangeAddress} returned contains a row part which spans all
  980. * rows, and a column part which specifies the contiguous range of
  981. * repeating columns.<p>
  982. *
  983. * If the Sheet does not have any repeating columns defined, null is
  984. * returned.
  985. *
  986. * @return an {@link CellRangeAddress} containing the repeating columns for
  987. * the Sheet, or null.
  988. */
  989. CellRangeAddress getRepeatingColumns();
  990. /**
  991. * Sets the repeating rows used when printing the sheet, as found in
  992. * File-&gt;PageSetup-&gt;Sheet.<p>
  993. *
  994. * Repeating rows cover a range of contiguous rows, e.g.:
  995. * <pre>
  996. * Sheet1!$1:$1
  997. * Sheet2!$5:$8</pre>
  998. * The parameter {@link CellRangeAddress} should specify a column part
  999. * which spans all columns, and a row part which specifies the contiguous
  1000. * range of repeating rows, e.g.:
  1001. * <pre>
  1002. * sheet.setRepeatingRows(CellRangeAddress.valueOf("2:3"));</pre>
  1003. * A null parameter value indicates that repeating rows should be removed
  1004. * from the Sheet:
  1005. * <pre>
  1006. * sheet.setRepeatingRows(null);</pre>
  1007. *
  1008. * @param rowRangeRef a {@link CellRangeAddress} containing the repeating
  1009. * rows for the Sheet, or null.
  1010. */
  1011. void setRepeatingRows(CellRangeAddress rowRangeRef);
  1012. /**
  1013. * Sets the repeating columns used when printing the sheet, as found in
  1014. * File-&gt;PageSetup-&gt;Sheet.<p>
  1015. *
  1016. * Repeating columns cover a range of contiguous columns, e.g.:
  1017. * <pre>
  1018. * Sheet1!$A:$A
  1019. * Sheet2!$C:$F</pre>
  1020. * The parameter {@link CellRangeAddress} should specify a row part
  1021. * which spans all rows, and a column part which specifies the contiguous
  1022. * range of repeating columns, e.g.:
  1023. * <pre>
  1024. * sheet.setRepeatingColumns(CellRangeAddress.valueOf("B:C"));</pre>
  1025. * A null parameter value indicates that repeating columns should be removed
  1026. * from the Sheet:
  1027. * <pre>
  1028. * sheet.setRepeatingColumns(null);</pre>
  1029. *
  1030. * @param columnRangeRef a {@link CellRangeAddress} containing the repeating
  1031. * columns for the Sheet, or null.
  1032. */
  1033. void setRepeatingColumns(CellRangeAddress columnRangeRef);
  1034. /**
  1035. * Returns the column outline level. Increased as you
  1036. * put it into more groups (outlines), reduced as
  1037. * you take it out of them.
  1038. */
  1039. int getColumnOutlineLevel(int columnIndex);
  1040. /**
  1041. * Get a Hyperlink in this sheet anchored at row, column
  1042. *
  1043. * @param row The 0-based index of the row to look at.
  1044. * @param column The 0-based index of the column to look at.
  1045. * @return hyperlink if there is a hyperlink anchored at row, column; otherwise returns null
  1046. */
  1047. Hyperlink getHyperlink(int row, int column);
  1048. /**
  1049. * Get a Hyperlink in this sheet located in a cell specified by {code addr}
  1050. *
  1051. * @param addr The address of the cell containing the hyperlink
  1052. * @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns {@code null}
  1053. * @since POI 3.15 beta 3
  1054. */
  1055. Hyperlink getHyperlink(CellAddress addr);
  1056. /**
  1057. * Get a list of Hyperlinks in this sheet
  1058. *
  1059. * @return Hyperlinks for the sheet
  1060. */
  1061. List<? extends Hyperlink> getHyperlinkList();
  1062. /**
  1063. * Return location of the active cell, e.g. {@code A1}.
  1064. *
  1065. * @return the location of the active cell.
  1066. * @since 3.14beta1
  1067. */
  1068. CellAddress getActiveCell();
  1069. /**
  1070. * Sets location of the active cell
  1071. *
  1072. * @param address the location of the active cell, e.g. {@code A1}.
  1073. * @since 3.14beta1
  1074. */
  1075. void setActiveCell(CellAddress address);
  1076. }