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.

CellFormatType.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package org.apache.poi.ss.format;
  2. /**
  3. * The different kinds of formats that the formatter understands.
  4. *
  5. * @author Ken Arnold, Industrious Media LLC
  6. */
  7. public enum CellFormatType {
  8. /** The general (default) format; also used for <tt>"General"</tt>. */
  9. GENERAL {
  10. CellFormatter formatter(String pattern) {
  11. return new CellGeneralFormatter();
  12. }
  13. boolean isSpecial(char ch) {
  14. return false;
  15. }
  16. },
  17. /** A numeric format. */
  18. NUMBER {
  19. boolean isSpecial(char ch) {
  20. return false;
  21. }
  22. CellFormatter formatter(String pattern) {
  23. return new CellNumberFormatter(pattern);
  24. }
  25. },
  26. /** A date format. */
  27. DATE {
  28. boolean isSpecial(char ch) {
  29. return ch == '\'' || (ch <= '\u007f' && Character.isLetter(ch));
  30. }
  31. CellFormatter formatter(String pattern) {
  32. return new CellDateFormatter(pattern);
  33. }
  34. },
  35. /** An elapsed time format. */
  36. ELAPSED {
  37. boolean isSpecial(char ch) {
  38. return false;
  39. }
  40. CellFormatter formatter(String pattern) {
  41. return new CellElapsedFormatter(pattern);
  42. }
  43. },
  44. /** A text format. */
  45. TEXT {
  46. boolean isSpecial(char ch) {
  47. return false;
  48. }
  49. CellFormatter formatter(String pattern) {
  50. return new CellTextFormatter(pattern);
  51. }
  52. };
  53. /**
  54. * Returns <tt>true</tt> if the format is special and needs to be quoted.
  55. *
  56. * @param ch The character to test.
  57. *
  58. * @return <tt>true</tt> if the format is special and needs to be quoted.
  59. */
  60. abstract boolean isSpecial(char ch);
  61. /**
  62. * Returns a new formatter of the appropriate type, for the given pattern.
  63. * The pattern must be appropriate for the type.
  64. *
  65. * @param pattern The pattern to use.
  66. *
  67. * @return A new formatter of the appropriate type, for the given pattern.
  68. */
  69. abstract CellFormatter formatter(String pattern);
  70. }