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 39KB

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