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.

BuiltinFormats.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /**
  17. * Utility to identify built-in formats. The following is a list of the formats as
  18. * returned by this class.<p>
  19. *<p>
  20. * 0, "General"<br>
  21. * 1, "0"<br>
  22. * 2, "0.00"<br>
  23. * 3, "#,##0"<br>
  24. * 4, "#,##0.00"<br>
  25. * 5, "$#,##0_);($#,##0)"<br>
  26. * 6, "$#,##0_);[Red]($#,##0)"<br>
  27. * 7, "$#,##0.00);($#,##0.00)"<br>
  28. * 8, "$#,##0.00_);[Red]($#,##0.00)"<br>
  29. * 9, "0%"<br>
  30. * 0xa, "0.00%"<br>
  31. * 0xb, "0.00E+00"<br>
  32. * 0xc, "# ?/?"<br>
  33. * 0xd, "# ??/??"<br>
  34. * 0xe, "m/d/yy"<br>
  35. * 0xf, "d-mmm-yy"<br>
  36. * 0x10, "d-mmm"<br>
  37. * 0x11, "mmm-yy"<br>
  38. * 0x12, "h:mm AM/PM"<br>
  39. * 0x13, "h:mm:ss AM/PM"<br>
  40. * 0x14, "h:mm"<br>
  41. * 0x15, "h:mm:ss"<br>
  42. * 0x16, "m/d/yy h:mm"<br>
  43. *<p>
  44. * // 0x17 - 0x24 reserved for international and undocumented
  45. * 0x25, "#,##0_);(#,##0)"<br>
  46. * 0x26, "#,##0_);[Red](#,##0)"<br>
  47. * 0x27, "#,##0.00_);(#,##0.00)"<br>
  48. * 0x28, "#,##0.00_);[Red](#,##0.00)"<br>
  49. * 0x29, "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)"<br>
  50. * 0x2a, "_($* #,##0_);_($* (#,##0);_($* \"-\"_);_(@_)"<br>
  51. * 0x2b, "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)"<br>
  52. * 0x2c, "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"<br>
  53. * 0x2d, "mm:ss"<br>
  54. * 0x2e, "[h]:mm:ss"<br>
  55. * 0x2f, "mm:ss.0"<br>
  56. * 0x30, "##0.0E+0"<br>
  57. * 0x31, "@" - This is text format.<br>
  58. * 0x31 "text" - Alias for "@"<br>
  59. * <p>
  60. */
  61. public final class BuiltinFormats {
  62. /**
  63. * The first user-defined number format starts at 164.
  64. */
  65. public static final int FIRST_USER_DEFINED_FORMAT_INDEX = 164;
  66. private final static String[] _formats = {
  67. "General",
  68. "0",
  69. "0.00",
  70. "#,##0",
  71. "#,##0.00",
  72. "\"$\"#,##0_);(\"$\"#,##0)",
  73. "\"$\"#,##0_);[Red](\"$\"#,##0)",
  74. "\"$\"#,##0.00_);(\"$\"#,##0.00)",
  75. "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)",
  76. "0%",
  77. "0.00%",
  78. "0.00E+00",
  79. "# ?/?",
  80. "# ??/??",
  81. "m/d/yy",
  82. "d-mmm-yy",
  83. "d-mmm",
  84. "mmm-yy",
  85. "h:mm AM/PM",
  86. "h:mm:ss AM/PM",
  87. "h:mm",
  88. "h:mm:ss",
  89. "m/d/yy h:mm",
  90. // 0x17 - 0x24 reserved for international and undocumented
  91. // TODO - one junit relies on these values which seems incorrect
  92. "reserved-0x17",
  93. "reserved-0x18",
  94. "reserved-0x19",
  95. "reserved-0x1A",
  96. "reserved-0x1B",
  97. "reserved-0x1C",
  98. "reserved-0x1D",
  99. "reserved-0x1E",
  100. "reserved-0x1F",
  101. "reserved-0x20",
  102. "reserved-0x21",
  103. "reserved-0x22",
  104. "reserved-0x23",
  105. "reserved-0x24",
  106. "#,##0_);(#,##0)",
  107. "#,##0_);[Red](#,##0)",
  108. "#,##0.00_);(#,##0.00)",
  109. "#,##0.00_);[Red](#,##0.00)",
  110. "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)",
  111. "_(\"$\"* #,##0_);_(\"$\"* (#,##0);_(\"$\"* \"-\"_);_(@_)",
  112. "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)",
  113. "_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)",
  114. "mm:ss",
  115. "[h]:mm:ss",
  116. "mm:ss.0",
  117. "##0.0E+0",
  118. "@"
  119. };
  120. /**
  121. * @return array of built-in data formats
  122. */
  123. public static String[] getAll() {
  124. return _formats.clone();
  125. }
  126. /**
  127. * Get the format string that matches the given format index
  128. *
  129. * @param index of a built in format
  130. * @return string represented at index of format or <code>null</code> if there is not a built-in format at that index
  131. */
  132. public static String getBuiltinFormat(int index) {
  133. if (index < 0 || index >=_formats.length) {
  134. return null;
  135. }
  136. return _formats[index];
  137. }
  138. /**
  139. * Get the format index that matches the given format string.<br>
  140. * Automatically converts "text" to excel's format string to represent text.
  141. *
  142. * @param pFmt string matching a built-in format
  143. * @return index of format or -1 if undefined.
  144. */
  145. public static int getBuiltinFormat(String pFmt) {
  146. String fmt = "TEXT".equalsIgnoreCase(pFmt) ? "@" : pFmt;
  147. int i = -1;
  148. for (String f : _formats) {
  149. i++;
  150. if (f.equals(fmt)) {
  151. return i;
  152. }
  153. }
  154. return -1;
  155. }
  156. }