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

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