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

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