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.

CellStyle.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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 org.apache.poi.util.Removal;
  17. public interface CellStyle {
  18. /**
  19. * get the index within the Workbook (sequence within the collection of ExtnededFormat objects)
  20. * @return unique index number of the underlying record this style represents (probably you don't care
  21. * unless you're comparing which one is which)
  22. */
  23. short getIndex();
  24. /**
  25. * set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}.
  26. * @see DataFormat
  27. */
  28. void setDataFormat(short fmt);
  29. /**
  30. * get the index of the data format. Built in formats are defined at {@link BuiltinFormats}.
  31. * @see DataFormat
  32. */
  33. short getDataFormat();
  34. /**
  35. * Get the format string
  36. */
  37. String getDataFormatString();
  38. /**
  39. * set the font for this style
  40. * @param font a font object created or retrieved from the Workbook object
  41. * @see Workbook#createFont()
  42. * @see Workbook#getFontAt(int)
  43. */
  44. void setFont(Font font);
  45. /**
  46. * gets the index of the font for this style
  47. * @see Workbook#getFontAt(short)
  48. * @deprecated use <code>getFontIndexAsInt()</code> instead
  49. */
  50. @Removal(version = "4.2")
  51. short getFontIndex();
  52. /**
  53. * gets the index of the font for this style
  54. * @see Workbook#getFontAt(int)
  55. * @since 4.0.0
  56. */
  57. int getFontIndexAsInt();
  58. /**
  59. * set the cell's using this style to be hidden
  60. * @param hidden - whether the cell using this style should be hidden
  61. */
  62. void setHidden(boolean hidden);
  63. /**
  64. * get whether the cell's using this style are to be hidden
  65. * @return hidden - whether the cell using this style should be hidden
  66. */
  67. boolean getHidden();
  68. /**
  69. * set the cell's using this style to be locked
  70. * @param locked - whether the cell using this style should be locked
  71. */
  72. void setLocked(boolean locked);
  73. /**
  74. * get whether the cell's using this style are to be locked
  75. * @return hidden - whether the cell using this style should be locked
  76. */
  77. boolean getLocked();
  78. /**
  79. * Turn on or off "Quote Prefix" or "123 Prefix" for the style,
  80. * which is used to tell Excel that the thing which looks like
  81. * a number or a formula shouldn't be treated as on.
  82. * Turning this on is somewhat (but not completely, see {@link IgnoredErrorType})
  83. * like prefixing the cell value with a ' in Excel
  84. */
  85. void setQuotePrefixed(boolean quotePrefix);
  86. /**
  87. * Is "Quote Prefix" or "123 Prefix" enabled for the cell?
  88. * Having this on is somewhat (but not completely, see {@link IgnoredErrorType})
  89. * like prefixing the cell value with a ' in Excel
  90. */
  91. boolean getQuotePrefixed();
  92. /**
  93. * set the type of horizontal alignment for the cell
  94. * @param align - the type of alignment
  95. */
  96. void setAlignment(HorizontalAlignment align);
  97. /**
  98. * get the type of horizontal alignment for the cell
  99. * @return align - the type of alignment
  100. */
  101. HorizontalAlignment getAlignment();
  102. /**
  103. * get the type of horizontal alignment for the cell
  104. * @return align - the type of alignment
  105. * @deprecated use <code>getAlignment()</code> instead
  106. */
  107. @Removal(version = "4.2")
  108. @Deprecated
  109. HorizontalAlignment getAlignmentEnum();
  110. /**
  111. * Set whether the text should be wrapped.
  112. * Setting this flag to <code>true</code> make all content visible
  113. * within a cell by displaying it on multiple lines
  114. *
  115. * @param wrapped wrap text or not
  116. */
  117. void setWrapText(boolean wrapped);
  118. /**
  119. * get whether the text should be wrapped
  120. * @return wrap text or not
  121. */
  122. boolean getWrapText();
  123. /**
  124. * set the type of vertical alignment for the cell
  125. * @param align the type of alignment
  126. */
  127. void setVerticalAlignment(VerticalAlignment align);
  128. /**
  129. * get the type of vertical alignment for the cell
  130. * @return align the type of alignment
  131. */
  132. VerticalAlignment getVerticalAlignment();
  133. /**
  134. * get the type of vertical alignment for the cell
  135. * @return align the type of alignment
  136. * @deprecated use <code>getVerticalAlignment()</code> instead
  137. */
  138. @Removal(version = "4.2")
  139. @Deprecated
  140. VerticalAlignment getVerticalAlignmentEnum();
  141. /**
  142. * set the degree of rotation for the text in the cell.
  143. *
  144. * Note: HSSF uses values from -90 to 90 degrees, whereas XSSF
  145. * uses values from 0 to 180 degrees. The implementations of this method will map between these two value-ranges
  146. * accordingly, however the corresponding getter is returning values in the range mandated by the current type
  147. * of Excel file-format that this CellStyle is applied to.
  148. *
  149. * @param rotation degrees (see note above)
  150. */
  151. void setRotation(short rotation);
  152. /**
  153. * get the degree of rotation for the text in the cell.
  154. *
  155. * Note: HSSF uses values from -90 to 90 degrees, whereas XSSF
  156. * uses values from 0 to 180 degrees. The implementations of this method will map between these two value-ranges
  157. * value-range as used by the type of Excel file-format that this CellStyle is applied to.
  158. *
  159. * @return rotation degrees (see note above)
  160. */
  161. short getRotation();
  162. /**
  163. * set the number of spaces to indent the text in the cell
  164. * @param indent - number of spaces
  165. */
  166. void setIndention(short indent);
  167. /**
  168. * get the number of spaces to indent the text in the cell
  169. * @return indent - number of spaces
  170. */
  171. short getIndention();
  172. /**
  173. * set the type of border to use for the left border of the cell
  174. * @param border type
  175. * @since POI 3.15
  176. */
  177. void setBorderLeft(BorderStyle border);
  178. /**
  179. * get the type of border to use for the left border of the cell
  180. * @return border type
  181. * @since POI 4.0.0
  182. */
  183. BorderStyle getBorderLeft();
  184. /**
  185. * get the type of border to use for the left border of the cell
  186. * @return border type
  187. * @since POI 3.15
  188. * @deprecated use <code>getBorderLeft()</code> instead
  189. */
  190. @Removal(version = "4.2")
  191. @Deprecated
  192. BorderStyle getBorderLeftEnum();
  193. /**
  194. * set the type of border to use for the right border of the cell
  195. * @param border type
  196. * @since POI 3.15
  197. */
  198. void setBorderRight(BorderStyle border);
  199. /**
  200. * get the type of border to use for the right border of the cell
  201. * @return border type
  202. * @since POI 4.0.0
  203. */
  204. BorderStyle getBorderRight();
  205. /**
  206. * get the type of border to use for the right border of the cell
  207. * @return border type
  208. * @since POI 3.15
  209. * @deprecated use <code>getBorderRight()</code> instead
  210. */
  211. @Removal(version = "4.2")
  212. @Deprecated
  213. BorderStyle getBorderRightEnum();
  214. /**
  215. * set the type of border to use for the top border of the cell
  216. * @param border type
  217. * @since POI 3.15
  218. */
  219. void setBorderTop(BorderStyle border);
  220. /**
  221. * get the type of border to use for the top border of the cell
  222. * @return border type
  223. * @since POI 4.0.0
  224. */
  225. BorderStyle getBorderTop();
  226. /**
  227. * get the type of border to use for the top border of the cell
  228. * @return border type
  229. * @since POI 3.15
  230. * @deprecated use <code>getBorderTop()</code> instead
  231. */
  232. @Removal(version = "4.2")
  233. @Deprecated
  234. BorderStyle getBorderTopEnum();
  235. /**
  236. * set the type of border to use for the bottom border of the cell
  237. * @param border type
  238. * @since POI 3.15
  239. */
  240. void setBorderBottom(BorderStyle border);
  241. /**
  242. * get the type of border to use for the bottom border of the cell
  243. * @return border type
  244. * @since POI 4.0.0
  245. */
  246. BorderStyle getBorderBottom();
  247. /**
  248. * get the type of border to use for the bottom border of the cell
  249. * @return border type
  250. * @since POI 3.15
  251. * @deprecated use <code>getBorderBottom()</code> instead
  252. */
  253. @Removal(version = "4.2")
  254. @Deprecated
  255. BorderStyle getBorderBottomEnum();
  256. /**
  257. * set the color to use for the left border
  258. * @param color The index of the color definition
  259. */
  260. void setLeftBorderColor(short color);
  261. /**
  262. * get the color to use for the left border
  263. */
  264. short getLeftBorderColor();
  265. /**
  266. * set the color to use for the right border
  267. * @param color The index of the color definition
  268. */
  269. void setRightBorderColor(short color);
  270. /**
  271. * get the color to use for the left border
  272. * @return the index of the color definition
  273. */
  274. short getRightBorderColor();
  275. /**
  276. * set the color to use for the top border
  277. * @param color The index of the color definition
  278. */
  279. void setTopBorderColor(short color);
  280. /**
  281. * get the color to use for the top border
  282. * @return the index of the color definition
  283. */
  284. short getTopBorderColor();
  285. /**
  286. * set the color to use for the bottom border
  287. * @param color The index of the color definition
  288. */
  289. void setBottomBorderColor(short color);
  290. /**
  291. * get the color to use for the left border
  292. * @return the index of the color definition
  293. */
  294. short getBottomBorderColor();
  295. /**
  296. * setting to one fills the cell with the foreground color... No idea about
  297. * other values
  298. *
  299. * @param fp fill pattern (set to {@link FillPatternType#SOLID_FOREGROUND} to fill w/foreground color)
  300. * @since POI 3.15 beta 3
  301. */
  302. void setFillPattern(FillPatternType fp);
  303. /**
  304. * Get the fill pattern
  305. *
  306. * @return the fill pattern, default value is {@link FillPatternType#NO_FILL}
  307. * @since POI 4.0.0
  308. */
  309. FillPatternType getFillPattern();
  310. /**
  311. * Get the fill pattern
  312. *
  313. * @return the fill pattern, default value is {@link FillPatternType#NO_FILL}
  314. * @since POI 3.15 beta 3
  315. * @deprecated use <code>getFillPattern()</code> instead
  316. */
  317. @Removal(version = "4.2")
  318. @Deprecated
  319. FillPatternType getFillPatternEnum();
  320. /**
  321. * set the background fill color.
  322. *
  323. * @param bg color
  324. */
  325. void setFillBackgroundColor(short bg);
  326. /**
  327. * get the background fill color, if the fill
  328. * is defined with an indexed color.
  329. * @return fill color index, or 0 if not indexed (XSSF only)
  330. */
  331. short getFillBackgroundColor();
  332. /**
  333. * Gets the color object representing the current
  334. * background fill, resolving indexes using
  335. * the supplied workbook.
  336. * This will work for both indexed and rgb
  337. * defined colors.
  338. */
  339. Color getFillBackgroundColorColor();
  340. /**
  341. * set the foreground fill color
  342. * <i>Note: Ensure Foreground color is set prior to background color.</i>
  343. * @param bg color
  344. */
  345. void setFillForegroundColor(short bg);
  346. /**
  347. * get the foreground fill color, if the fill
  348. * is defined with an indexed color.
  349. * @return fill color, or 0 if not indexed (XSSF only)
  350. */
  351. short getFillForegroundColor();
  352. /**
  353. * Gets the color object representing the current
  354. * foreground fill, resolving indexes using
  355. * the supplied workbook.
  356. * This will work for both indexed and rgb
  357. * defined colors.
  358. */
  359. Color getFillForegroundColorColor();
  360. /**
  361. * Clones all the style information from another
  362. * CellStyle, onto this one. This
  363. * CellStyle will then have all the same
  364. * properties as the source, but the two may
  365. * be edited independently.
  366. * Any stylings on this CellStyle will be lost!
  367. *
  368. * The source CellStyle could be from another
  369. * Workbook if you like. This allows you to
  370. * copy styles from one Workbook to another.
  371. *
  372. * However, both of the CellStyles will need
  373. * to be of the same type (HSSFCellStyle or
  374. * XSSFCellStyle)
  375. */
  376. void cloneStyleFrom(CellStyle source);
  377. /**
  378. * Controls if the Cell should be auto-sized
  379. * to shrink to fit if the text is too long
  380. */
  381. void setShrinkToFit(boolean shrinkToFit);
  382. /**
  383. * Should the Cell be auto-sized by Excel to shrink
  384. * it to fit if this text is too long?
  385. */
  386. boolean getShrinkToFit();
  387. }