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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.usermodel;
  16. import java.util.Iterator;
  17. import org.apache.poi.hssf.util.PaneInformation;
  18. import org.apache.poi.ss.util.CellRangeAddress;
  19. /**
  20. * High level representation of a Excel worksheet.
  21. *
  22. * <p>
  23. * Sheets are the central structures within a workbook, and are where a user does most of his spreadsheet work.
  24. * The most common type of sheet is the worksheet, which is represented as a grid of cells. Worksheet cells can
  25. * contain text, numbers, dates, and formulas. Cells can also be formatted.
  26. * </p>
  27. */
  28. public interface Sheet extends Iterable<Row> {
  29. /* Constants for margins */
  30. public static final short LeftMargin = 0;
  31. public static final short RightMargin = 1;
  32. public static final short TopMargin = 2;
  33. public static final short BottomMargin = 3;
  34. public static final short HeaderMargin = 4;
  35. public static final short FooterMargin = 5;
  36. public static final byte PANE_LOWER_RIGHT = (byte) 0;
  37. public static final byte PANE_UPPER_RIGHT = (byte) 1;
  38. public static final byte PANE_LOWER_LEFT = (byte) 2;
  39. public static final byte PANE_UPPER_LEFT = (byte) 3;
  40. /**
  41. * Create a new row within the sheet and return the high level representation
  42. *
  43. * @param rownum row number
  44. * @return high level Row object representing a row in the sheet
  45. * @see #removeRow(Row)
  46. */
  47. Row createRow(int rownum);
  48. /**
  49. * Remove a row from this sheet. All cells contained in the row are removed as well
  50. *
  51. * @param row representing a row to remove.
  52. */
  53. void removeRow(Row row);
  54. /**
  55. * Returns the logical row (not physical) 0-based. If you ask for a row that is not
  56. * defined you get a null. This is to say row 4 represents the fifth row on a sheet.
  57. *
  58. * @param rownum row to get (0-based)
  59. * @return Row representing the rownumber or null if its not defined on the sheet
  60. */
  61. Row getRow(int rownum);
  62. /**
  63. * Returns the number of physically defined rows (NOT the number of rows in the sheet)
  64. *
  65. * @return the number of physically defined rows in this sheet
  66. */
  67. int getPhysicalNumberOfRows();
  68. /**
  69. * Gets the first row on the sheet
  70. *
  71. * @return the number of the first logical row on the sheet (0-based)
  72. */
  73. int getFirstRowNum();
  74. /**
  75. * Gets the last row on the sheet
  76. *
  77. * @return last row contained n this sheet (0-based)
  78. */
  79. int getLastRowNum();
  80. /**
  81. * Get the visibility state for a given column
  82. *
  83. * @param columnIndex - the column to get (0-based)
  84. * @param hidden - the visiblity state of the column
  85. */
  86. void setColumnHidden(int columnIndex, boolean hidden);
  87. /**
  88. * Get the hidden state for a given column
  89. *
  90. * @param columnIndex - the column to set (0-based)
  91. * @return hidden - <code>false</code> if the column is visible
  92. */
  93. boolean isColumnHidden(int columnIndex);
  94. /**
  95. * Sets whether the worksheet is displayed from right to left instead of from left to right.
  96. *
  97. * @param value true for right to left, false otherwise.
  98. */
  99. public void setRightToLeft(boolean value);
  100. /**
  101. * Whether the text is displayed in right-to-left mode in the window
  102. *
  103. * @return whether the text is displayed in right-to-left mode in the window
  104. */
  105. public boolean isRightToLeft();
  106. /**
  107. * Set the width (in units of 1/256th of a character width)
  108. *
  109. * <p>
  110. * The maximum column width for an individual cell is 255 characters.
  111. * This value represents the number of characters that can be displayed
  112. * in a cell that is formatted with the standard font (first font in the workbook).
  113. * </p>
  114. *
  115. * <p>
  116. * Character width is defined as the maximum digit width
  117. * of the numbers <code>0, 1, 2, ... 9</code> as rendered
  118. * using the default font (first font in the workbook).
  119. * <br/>
  120. * Unless you are using a very special font, the default character is '0' (zero),
  121. * this is true for Arial (default font font in HSSF) and Calibri (default font in XSSF)
  122. * </p>
  123. *
  124. * <p>
  125. * Please note, that the width set by this method includes 4 pixels of margin padding (two on each side),
  126. * plus 1 pixel padding for the gridlines (Section 3.3.1.12 of the OOXML spec).
  127. * This results is a slightly less value of visible characters than passed to this method (approx. 1/2 of a character).
  128. * </p>
  129. * <p>
  130. * To compute the actual number of visible characters,
  131. * Excel uses the following formula (Section 3.3.1.12 of the OOXML spec):
  132. * </p>
  133. * <code>
  134. * width = Truncate([{Number of Visible Characters} *
  135. * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256
  136. * </code>
  137. * <p>Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi).
  138. * If you set a column width to be eight characters wide, e.g. <code>setColumnWidth(columnIndex, 8*256)</code>,
  139. * then the actual value of visible characters (the value shown in Excel) is derived from the following equation:
  140. * <code>
  141. Truncate([numChars*7+5]/7*256)/256 = 8;
  142. * </code>
  143. *
  144. * which gives <code>7.29</code>.
  145. *
  146. * @param columnIndex - the column to set (0-based)
  147. * @param width - the width in units of 1/256th of a character width
  148. * @throws IllegalArgumentException if width > 255*256 (the maximum column width in Excel is 255 characters)
  149. */
  150. void setColumnWidth(int columnIndex, int width);
  151. /**
  152. * get the width (in units of 1/256th of a character width )
  153. *
  154. * <p>
  155. * Character width is defined as the maximum digit width
  156. * of the numbers <code>0, 1, 2, ... 9</code> as rendered
  157. * using the default font (first font in the workbook)
  158. * </p>
  159. *
  160. * @param columnIndex - the column to set (0-based)
  161. * @return width - the width in units of 1/256th of a character width
  162. */
  163. int getColumnWidth(int columnIndex);
  164. /**
  165. * Set the default column width for the sheet (if the columns do not define their own width)
  166. * in characters
  167. *
  168. * @param width default column width measured in characters
  169. */
  170. void setDefaultColumnWidth(int width);
  171. /**
  172. * Get the default column width for the sheet (if the columns do not define their own width)
  173. * in characters
  174. *
  175. * @return default column width measured in characters
  176. */
  177. int getDefaultColumnWidth();
  178. /**
  179. * Get the default row height for the sheet (if the rows do not define their own height) in
  180. * twips (1/20 of a point)
  181. *
  182. * @return default row height measured in twips (1/20 of a point)
  183. */
  184. short getDefaultRowHeight();
  185. /**
  186. * Get the default row height for the sheet (if the rows do not define their own height) in
  187. * points.
  188. *
  189. * @return default row height in points
  190. */
  191. float getDefaultRowHeightInPoints();
  192. /**
  193. * Set the default row height for the sheet (if the rows do not define their own height) in
  194. * twips (1/20 of a point)
  195. *
  196. * @param height default row height measured in twips (1/20 of a point)
  197. */
  198. void setDefaultRowHeight(short height);
  199. /**
  200. * Set the default row height for the sheet (if the rows do not define their own height) in
  201. * points
  202. * @param height default row height
  203. */
  204. void setDefaultRowHeightInPoints(float height);
  205. /**
  206. * Returns the CellStyle that applies to the given
  207. * (0 based) column, or null if no style has been
  208. * set for that column
  209. */
  210. public CellStyle getColumnStyle(int column);
  211. /**
  212. * Sets the CellStyle that applies to the given
  213. * (0 based) column.
  214. */
  215. // public CellStyle setColumnStyle(int column, CellStyle style);
  216. /**
  217. * Adds a merged region of cells (hence those cells form one)
  218. *
  219. * @param region (rowfrom/colfrom-rowto/colto) to merge
  220. * @return index of this region
  221. */
  222. int addMergedRegion(CellRangeAddress region);
  223. /**
  224. * Determines whether the output is vertically centered on the page.
  225. *
  226. * @param value true to vertically center, false otherwise.
  227. */
  228. void setVerticallyCenter(boolean value);
  229. /**
  230. * Determines whether the output is horizontally centered on the page.
  231. *
  232. * @param value true to horizontally center, false otherwise.
  233. */
  234. void setHorizontallyCenter(boolean value);
  235. /**
  236. * Determine whether printed output for this sheet will be horizontally centered.
  237. */
  238. boolean getHorizontallyCenter();
  239. /**
  240. * Determine whether printed output for this sheet will be vertically centered.
  241. */
  242. boolean getVerticallyCenter();
  243. /**
  244. * Removes a merged region of cells (hence letting them free)
  245. *
  246. * @param index of the region to unmerge
  247. */
  248. void removeMergedRegion(int index);
  249. /**
  250. * Returns the number of merged regions
  251. *
  252. * @return number of merged regions
  253. */
  254. int getNumMergedRegions();
  255. /**
  256. * Returns the merged region at the specified index
  257. *
  258. * @return the merged region at the specified index
  259. */
  260. public CellRangeAddress getMergedRegion(int index);
  261. /**
  262. * Returns an iterator of the physical rows
  263. *
  264. * @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
  265. * be the third row if say for instance the second row is undefined.
  266. */
  267. Iterator<Row> rowIterator();
  268. /**
  269. * Control if Excel should be asked to recalculate all formulas on this sheet
  270. * when the workbook is opened.
  271. *
  272. * <p>
  273. * Calculating the formula values with {@link FormulaEvaluator} is the
  274. * recommended solution, but this may be used for certain cases where
  275. * evaluation in POI is not possible.
  276. * </p>
  277. *
  278. * To force recalcuation of formulas in the entire workbook
  279. * use {@link Workbook#setForceFormulaRecalculation(boolean)} instead.
  280. *
  281. * @param value true if the application will perform a full recalculation of
  282. * this worksheet values when the workbook is opened
  283. *
  284. * @see Workbook#setForceFormulaRecalculation(boolean)
  285. */
  286. void setForceFormulaRecalculation(boolean value);
  287. /**
  288. * Whether Excel will be asked to recalculate all formulas in this sheet when the
  289. * workbook is opened.
  290. */
  291. boolean getForceFormulaRecalculation();
  292. /**
  293. * Flag indicating whether the sheet displays Automatic Page Breaks.
  294. *
  295. * @param value <code>true</code> if the sheet displays Automatic Page Breaks.
  296. */
  297. void setAutobreaks(boolean value);
  298. /**
  299. * Set whether to display the guts or not
  300. *
  301. * @param value - guts or no guts
  302. */
  303. void setDisplayGuts(boolean value);
  304. /**
  305. * Set whether the window should show 0 (zero) in cells containing zero value.
  306. * When false, cells with zero value appear blank instead of showing the number zero.
  307. *
  308. * @param value whether to display or hide all zero values on the worksheet
  309. */
  310. void setDisplayZeros(boolean value);
  311. /**
  312. * Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value.
  313. * When false, cells with zero value appear blank instead of showing the number zero.
  314. *
  315. * @return whether all zero values on the worksheet are displayed
  316. */
  317. boolean isDisplayZeros();
  318. /**
  319. * Flag indicating whether the Fit to Page print option is enabled.
  320. *
  321. * @param value <code>true</code> if the Fit to Page print option is enabled.
  322. */
  323. void setFitToPage(boolean value);
  324. /**
  325. * Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
  326. *
  327. * <p>
  328. * When true a summary row is inserted below the detailed data being summarized and a
  329. * new outline level is established on that row.
  330. * </p>
  331. * <p>
  332. * When false a summary row is inserted above the detailed data being summarized and a new outline level
  333. * is established on that row.
  334. * </p>
  335. * @param value <code>true</code> if row summaries appear below detail in the outline
  336. */
  337. void setRowSumsBelow(boolean value);
  338. /**
  339. * Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.
  340. *
  341. * <p>
  342. * When true a summary column is inserted to the right of the detailed data being summarized
  343. * and a new outline level is established on that column.
  344. * </p>
  345. * <p>
  346. * When false a summary column is inserted to the left of the detailed data being
  347. * summarized and a new outline level is established on that column.
  348. * </p>
  349. * @param value <code>true</code> if col summaries appear right of the detail in the outline
  350. */
  351. void setRowSumsRight(boolean value);
  352. /**
  353. * Flag indicating whether the sheet displays Automatic Page Breaks.
  354. *
  355. * @return <code>true</code> if the sheet displays Automatic Page Breaks.
  356. */
  357. boolean getAutobreaks();
  358. /**
  359. * Get whether to display the guts or not,
  360. * default value is true
  361. *
  362. * @return boolean - guts or no guts
  363. */
  364. boolean getDisplayGuts();
  365. /**
  366. * Flag indicating whether the Fit to Page print option is enabled.
  367. *
  368. * @return <code>true</code> if the Fit to Page print option is enabled.
  369. */
  370. boolean getFitToPage();
  371. /**
  372. * Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
  373. *
  374. * <p>
  375. * When true a summary row is inserted below the detailed data being summarized and a
  376. * new outline level is established on that row.
  377. * </p>
  378. * <p>
  379. * When false a summary row is inserted above the detailed data being summarized and a new outline level
  380. * is established on that row.
  381. * </p>
  382. * @return <code>true</code> if row summaries appear below detail in the outline
  383. */
  384. boolean getRowSumsBelow();
  385. /**
  386. * Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.
  387. *
  388. * <p>
  389. * When true a summary column is inserted to the right of the detailed data being summarized
  390. * and a new outline level is established on that column.
  391. * </p>
  392. * <p>
  393. * When false a summary column is inserted to the left of the detailed data being
  394. * summarized and a new outline level is established on that column.
  395. * </p>
  396. * @return <code>true</code> if col summaries appear right of the detail in the outline
  397. */
  398. boolean getRowSumsRight();
  399. /**
  400. * Gets the flag indicating whether this sheet displays the lines
  401. * between rows and columns to make editing and reading easier.
  402. *
  403. * @return <code>true</code> if this sheet displays gridlines.
  404. * @see #isPrintGridlines() to check if printing of gridlines is turned on or off
  405. */
  406. boolean isPrintGridlines();
  407. /**
  408. * Sets the flag indicating whether this sheet should display the lines
  409. * between rows and columns to make editing and reading easier.
  410. * To turn printing of gridlines use {@link #setPrintGridlines(boolean)}
  411. *
  412. *
  413. * @param show <code>true</code> if this sheet should display gridlines.
  414. * @see #setPrintGridlines(boolean)
  415. */
  416. void setPrintGridlines(boolean show);
  417. /**
  418. * Gets the print setup object.
  419. *
  420. * @return The user model for the print setup object.
  421. */
  422. PrintSetup getPrintSetup();
  423. /**
  424. * Gets the user model for the default document header.
  425. * <p/>
  426. * Note that XSSF offers more kinds of document headers than HSSF does
  427. * </p>
  428. * @return the document header. Never <code>null</code>
  429. */
  430. Header getHeader();
  431. /**
  432. * Gets the user model for the default document footer.
  433. * <p/>
  434. * Note that XSSF offers more kinds of document footers than HSSF does.
  435. *
  436. * @return the document footer. Never <code>null</code>
  437. */
  438. Footer getFooter();
  439. /**
  440. * Sets a flag indicating whether this sheet is selected.
  441. *<p>
  442. * Note: multiple sheets can be selected, but only one sheet can be active at one time.
  443. *</p>
  444. * @param value <code>true</code> if this sheet is selected
  445. * @see Workbook#setActiveSheet(int)
  446. */
  447. void setSelected(boolean value);
  448. /**
  449. * Gets the size of the margin in inches.
  450. *
  451. * @param margin which margin to get
  452. * @return the size of the margin
  453. */
  454. double getMargin(short margin);
  455. /**
  456. * Sets the size of the margin in inches.
  457. *
  458. * @param margin which margin to get
  459. * @param size the size of the margin
  460. */
  461. void setMargin(short margin, double size);
  462. /**
  463. * Answer whether protection is enabled or disabled
  464. *
  465. * @return true => protection enabled; false => protection disabled
  466. */
  467. boolean getProtect();
  468. /**
  469. * Sets the protection enabled as well as the password
  470. * @param password to set for protection. Pass <code>null</code> to remove protection
  471. */
  472. public void protectSheet(String password);
  473. /**
  474. * Answer whether scenario protection is enabled or disabled
  475. *
  476. * @return true => protection enabled; false => protection disabled
  477. */
  478. boolean getScenarioProtect();
  479. /**
  480. * Sets the zoom magnication for the sheet. The zoom is expressed as a
  481. * fraction. For example to express a zoom of 75% use 3 for the numerator
  482. * and 4 for the denominator.
  483. *
  484. * @param numerator The numerator for the zoom magnification.
  485. * @param denominator The denominator for the zoom magnification.
  486. */
  487. void setZoom(int numerator, int denominator);
  488. /**
  489. * The top row in the visible view when the sheet is
  490. * first viewed after opening it in a viewer
  491. *
  492. * @return short indicating the rownum (0 based) of the top row
  493. */
  494. short getTopRow();
  495. /**
  496. * The left col in the visible view when the sheet is
  497. * first viewed after opening it in a viewer
  498. *
  499. * @return short indicating the rownum (0 based) of the top row
  500. */
  501. short getLeftCol();
  502. /**
  503. * Sets desktop window pane display area, when the
  504. * file is first opened in a viewer.
  505. *
  506. * @param toprow the top row to show in desktop window pane
  507. * @param leftcol the left column to show in desktop window pane
  508. */
  509. void showInPane(short toprow, short leftcol);
  510. /**
  511. * Shifts rows between startRow and endRow n number of rows.
  512. * If you use a negative number, it will shift rows up.
  513. * Code ensures that rows don't wrap around.
  514. *
  515. * Calls shiftRows(startRow, endRow, n, false, false);
  516. *
  517. * <p>
  518. * Additionally shifts merged regions that are completely defined in these
  519. * rows (ie. merged 2 cells on a row to be shifted).
  520. * @param startRow the row to start shifting
  521. * @param endRow the row to end shifting
  522. * @param n the number of rows to shift
  523. */
  524. void shiftRows(int startRow, int endRow, int n);
  525. /**
  526. * Shifts rows between startRow and endRow n number of rows.
  527. * If you use a negative number, it will shift rows up.
  528. * Code ensures that rows don't wrap around
  529. *
  530. * <p>
  531. * Additionally shifts merged regions that are completely defined in these
  532. * rows (ie. merged 2 cells on a row to be shifted).
  533. * <p>
  534. * @param startRow the row to start shifting
  535. * @param endRow the row to end shifting
  536. * @param n the number of rows to shift
  537. * @param copyRowHeight whether to copy the row height during the shift
  538. * @param resetOriginalRowHeight whether to set the original row's height to the default
  539. */
  540. void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight);
  541. /**
  542. * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
  543. * <p>
  544. * If both colSplit and rowSplit are zero then the existing freeze pane is removed
  545. * </p>
  546. * @param colSplit Horizonatal position of split.
  547. * @param rowSplit Vertical position of split.
  548. * @param leftmostColumn Left column visible in right pane.
  549. * @param topRow Top row visible in bottom pane
  550. */
  551. void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow);
  552. /**
  553. * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
  554. * <p>
  555. * If both colSplit and rowSplit are zero then the existing freeze pane is removed
  556. * </p>
  557. * @param colSplit Horizonatal position of split.
  558. * @param rowSplit Vertical position of split.
  559. */
  560. void createFreezePane(int colSplit, int rowSplit);
  561. /**
  562. * Creates a split pane. Any existing freezepane or split pane is overwritten.
  563. * @param xSplitPos Horizonatal position of split (in 1/20th of a point).
  564. * @param ySplitPos Vertical position of split (in 1/20th of a point).
  565. * @param topRow Top row visible in bottom pane
  566. * @param leftmostColumn Left column visible in right pane.
  567. * @param activePane Active pane. One of: PANE_LOWER_RIGHT,
  568. * PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT
  569. * @see #PANE_LOWER_LEFT
  570. * @see #PANE_LOWER_RIGHT
  571. * @see #PANE_UPPER_LEFT
  572. * @see #PANE_UPPER_RIGHT
  573. */
  574. void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane);
  575. /**
  576. * Returns the information regarding the currently configured pane (split or freeze)
  577. *
  578. * @return null if no pane configured, or the pane information.
  579. */
  580. PaneInformation getPaneInformation();
  581. /**
  582. * Sets whether the gridlines are shown in a viewer
  583. *
  584. * @param show whether to show gridlines or not
  585. */
  586. void setDisplayGridlines(boolean show);
  587. /**
  588. * Returns if gridlines are displayed
  589. *
  590. * @return whether gridlines are displayed
  591. */
  592. boolean isDisplayGridlines();
  593. /**
  594. * Sets whether the formulas are shown in a viewer
  595. *
  596. * @param show whether to show formulas or not
  597. */
  598. void setDisplayFormulas(boolean show);
  599. /**
  600. * Returns if formulas are displayed
  601. *
  602. * @return whether formulas are displayed
  603. */
  604. boolean isDisplayFormulas();
  605. /**
  606. * Sets whether the RowColHeadings are shown in a viewer
  607. *
  608. * @param show whether to show RowColHeadings or not
  609. */
  610. void setDisplayRowColHeadings(boolean show);
  611. /**
  612. * Returns if RowColHeadings are displayed.
  613. * @return whether RowColHeadings are displayed
  614. */
  615. boolean isDisplayRowColHeadings();
  616. /**
  617. * Sets a page break at the indicated row
  618. * Breaks occur above the specified row and left of the specified column inclusive.
  619. *
  620. * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
  621. * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
  622. * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
  623. * and rows starting with rownum=4 in the second.
  624. *
  625. * @param row the row to break, inclusive
  626. */
  627. void setRowBreak(int row);
  628. /**
  629. * Determines if there is a page break at the indicated row
  630. * @param row FIXME: Document this!
  631. * @return FIXME: Document this!
  632. */
  633. boolean isRowBroken(int row);
  634. /**
  635. * Removes the page break at the indicated row
  636. * @param row
  637. */
  638. void removeRowBreak(int row);
  639. /**
  640. * Retrieves all the horizontal page breaks
  641. * @return all the horizontal page breaks, or null if there are no row page breaks
  642. */
  643. int[] getRowBreaks();
  644. /**
  645. * Retrieves all the vertical page breaks
  646. * @return all the vertical page breaks, or null if there are no column page breaks
  647. */
  648. int[] getColumnBreaks();
  649. /**
  650. * Sets a page break at the indicated column.
  651. * Breaks occur above the specified row and left of the specified column inclusive.
  652. *
  653. * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
  654. * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
  655. * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
  656. * and rows starting with rownum=4 in the second.
  657. *
  658. * @param column the column to break, inclusive
  659. */
  660. void setColumnBreak(int column);
  661. /**
  662. * Determines if there is a page break at the indicated column
  663. * @param column FIXME: Document this!
  664. * @return FIXME: Document this!
  665. */
  666. boolean isColumnBroken(int column);
  667. /**
  668. * Removes a page break at the indicated column
  669. * @param column
  670. */
  671. void removeColumnBreak(int column);
  672. /**
  673. * Expands or collapses a column group.
  674. *
  675. * @param columnNumber One of the columns in the group.
  676. * @param collapsed true = collapse group, false = expand group.
  677. */
  678. void setColumnGroupCollapsed(int columnNumber, boolean collapsed);
  679. /**
  680. * Create an outline for the provided column range.
  681. *
  682. * @param fromColumn beginning of the column range.
  683. * @param toColumn end of the column range.
  684. */
  685. void groupColumn(int fromColumn, int toColumn);
  686. /**
  687. * Ungroup a range of columns that were previously groupped
  688. *
  689. * @param fromColumn start column (0-based)
  690. * @param toColumn end column (0-based)
  691. */
  692. void ungroupColumn(int fromColumn, int toColumn);
  693. /**
  694. * Tie a range of rows together so that they can be collapsed or expanded
  695. *
  696. * @param fromRow start row (0-based)
  697. * @param toRow end row (0-based)
  698. */
  699. void groupRow(int fromRow, int toRow);
  700. /**
  701. * Ungroup a range of rows that were previously groupped
  702. *
  703. * @param fromRow start row (0-based)
  704. * @param toRow end row (0-based)
  705. */
  706. void ungroupRow(int fromRow, int toRow);
  707. /**
  708. * Set view state of a groupped range of rows
  709. *
  710. * @param row start row of a groupped range of rows (0-based)
  711. * @param collapse whether to expand/collapse the detail rows
  712. */
  713. void setRowGroupCollapsed(int row, boolean collapse);
  714. /**
  715. * Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
  716. *
  717. * @param column the column index
  718. * @param style the style to set
  719. */
  720. void setDefaultColumnStyle(int column, CellStyle style);
  721. /**
  722. * Adjusts the column width to fit the contents.
  723. *
  724. * <p>
  725. * This process can be relatively slow on large sheets, so this should
  726. * normally only be called once per column, at the end of your
  727. * processing.
  728. * </p>
  729. * You can specify whether the content of merged cells should be considered or ignored.
  730. * Default is to ignore merged cells.
  731. *
  732. * @param column the column index
  733. */
  734. void autoSizeColumn(int column);
  735. /**
  736. * Adjusts the column width to fit the contents.
  737. * <p>
  738. * This process can be relatively slow on large sheets, so this should
  739. * normally only be called once per column, at the end of your
  740. * processing.
  741. * </p>
  742. * You can specify whether the content of merged cells should be considered or ignored.
  743. * Default is to ignore merged cells.
  744. *
  745. * @param column the column index
  746. * @param useMergedCells whether to use the contents of merged cells when calculating the width of the column
  747. */
  748. void autoSizeColumn(int column, boolean useMergedCells);
  749. /**
  750. * Returns cell comment for the specified row and column
  751. *
  752. * @return cell comment or <code>null</code> if not found
  753. */
  754. Comment getCellComment(int row, int column);
  755. /**
  756. * Creates the top-level drawing patriarch.
  757. *
  758. * @return The new drawing patriarch.
  759. */
  760. Drawing createDrawingPatriarch();
  761. /**
  762. * Return the parent workbook
  763. *
  764. * @return the parent workbook
  765. */
  766. Workbook getWorkbook();
  767. /**
  768. * Returns the name of this sheet
  769. *
  770. * @return the name of this sheet
  771. */
  772. String getSheetName();
  773. /**
  774. * Note - this is not the same as whether the sheet is focused (isActive)
  775. * @return <code>true</code> if this sheet is currently selected
  776. */
  777. boolean isSelected();
  778. /**
  779. * Sets array formula to specified region for result.
  780. *
  781. * @param formula text representation of the formula
  782. * @param range Region of array formula for result.
  783. * @return the {@link CellRange} of cells affected by this change
  784. */
  785. CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress range);
  786. /**
  787. * Remove a Array Formula from this sheet. All cells contained in the Array Formula range are removed as well
  788. *
  789. * @param cell any cell within Array Formula range
  790. * @return the {@link CellRange} of cells affected by this change
  791. */
  792. CellRange<? extends Cell> removeArrayFormula(Cell cell);
  793. public DataValidationHelper getDataValidationHelper();
  794. /**
  795. * Creates a data validation object
  796. * @param dataValidation The Data validation object settings
  797. */
  798. public void addValidationData(DataValidation dataValidation);
  799. /**
  800. * Enable filtering for a range of cells
  801. *
  802. * @param range the range of cells to filter
  803. */
  804. AutoFilter setAutoFilter(CellRangeAddress range);
  805. /**
  806. * The 'Conditional Formatting' facet for this <tt>Sheet</tt>
  807. *
  808. * @return conditional formatting rule for this sheet
  809. */
  810. SheetConditionalFormatting getSheetConditionalFormatting();
  811. /**
  812. * Gets the repeating rows used when printing the sheet, as found in
  813. * File->PageSetup->Sheet.
  814. * <p/>
  815. * Repeating rows cover a range of contiguous rows, e.g.:
  816. * <pre>
  817. * Sheet1!$1:$1
  818. * Sheet2!$5:$8
  819. * </pre>
  820. * The {@link CellRangeAddress} returned contains a column part which spans
  821. * all columns, and a row part which specifies the contiguous range of
  822. * repeating rows.
  823. * <p/>
  824. * If the Sheet does not have any repeating rows defined, null is returned.
  825. *
  826. * @return an {@link CellRangeAddress} containing the repeating rows for the
  827. * Sheet, or null.
  828. */
  829. CellRangeAddress getRepeatingRows();
  830. /**
  831. * Gets the repeating columns used when printing the sheet, as found in
  832. * File->PageSetup->Sheet.
  833. * <p/>
  834. * Repeating columns cover a range of contiguous columns, e.g.:
  835. * <pre>
  836. * Sheet1!$A:$A
  837. * Sheet2!$C:$F
  838. * </pre>
  839. * The {@link CellRangeAddress} returned contains a row part which spans all
  840. * rows, and a column part which specifies the contiguous range of
  841. * repeating columns.
  842. * <p/>
  843. * If the Sheet does not have any repeating columns defined, null is
  844. * returned.
  845. *
  846. * @return an {@link CellRangeAddress} containing the repeating columns for the
  847. * Sheet, or null.
  848. */
  849. CellRangeAddress getRepeatingColumns();
  850. }