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.

HSSFRecordTypes.java 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.hssf.record;
  20. import java.util.Arrays;
  21. import java.util.Map;
  22. import java.util.function.Function;
  23. import java.util.stream.Collectors;
  24. import org.apache.poi.hssf.record.chart.*;
  25. import org.apache.poi.hssf.record.pivottable.DataItemRecord;
  26. import org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord;
  27. import org.apache.poi.hssf.record.pivottable.PageItemRecord;
  28. import org.apache.poi.hssf.record.pivottable.StreamIDRecord;
  29. import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
  30. import org.apache.poi.hssf.record.pivottable.ViewFieldsRecord;
  31. import org.apache.poi.hssf.record.pivottable.ViewSourceRecord;
  32. public enum HSSFRecordTypes {
  33. UNKNOWN(-1, UnknownRecord.class, UnknownRecord::new, false),
  34. FORMULA(0x0006, FormulaRecord.class, FormulaRecord::new),
  35. EOF(0x000A, EOFRecord.class, EOFRecord::new),
  36. CALC_COUNT(0x000C, CalcCountRecord.class, CalcCountRecord::new),
  37. CALC_MODE(0x000D, CalcModeRecord.class, CalcModeRecord::new),
  38. PRECISION(0x000E, PrecisionRecord.class, PrecisionRecord::new),
  39. REF_MODE(0x000F, RefModeRecord.class, RefModeRecord::new),
  40. DELTA(0x0010, DeltaRecord.class, DeltaRecord::new),
  41. ITERATION(0x0011, IterationRecord.class, IterationRecord::new),
  42. PROTECT(0x0012, ProtectRecord.class, ProtectRecord::new),
  43. PASSWORD(0x0013, PasswordRecord.class, PasswordRecord::new),
  44. HEADER(0x0014, HeaderRecord.class, HeaderRecord::new),
  45. FOOTER(0x0015, FooterRecord.class, FooterRecord::new),
  46. EXTERN_SHEET(0x0017, ExternSheetRecord.class, ExternSheetRecord::new),
  47. NAME(0x0018, NameRecord.class, NameRecord::new),
  48. WINDOW_PROTECT(0x0019, WindowProtectRecord.class, WindowProtectRecord::new),
  49. VERTICAL_PAGE_BREAK(0x001A, VerticalPageBreakRecord.class, VerticalPageBreakRecord::new),
  50. HORIZONTAL_PAGE_BREAK(0x001B, HorizontalPageBreakRecord.class, HorizontalPageBreakRecord::new),
  51. NOTE(0x001C, NoteRecord.class, NoteRecord::new),
  52. SELECTION(0x001D, SelectionRecord.class, SelectionRecord::new),
  53. DATE_WINDOW_1904(0x0022, DateWindow1904Record.class, DateWindow1904Record::new),
  54. EXTERNAL_NAME(0x0023, ExternalNameRecord.class, ExternalNameRecord::new),
  55. LEFT_MARGIN(0x0026, LeftMarginRecord.class, LeftMarginRecord::new),
  56. RIGHT_MARGIN(0x0027, RightMarginRecord.class, RightMarginRecord::new),
  57. TOP_MARGIN(0x0028, TopMarginRecord.class, TopMarginRecord::new),
  58. BOTTOM_MARGIN(0x0029, BottomMarginRecord.class, BottomMarginRecord::new),
  59. PRINT_HEADERS(0x002A, PrintHeadersRecord.class, PrintHeadersRecord::new),
  60. PRINT_GRIDLINES(0X002B, PrintGridlinesRecord.class, PrintGridlinesRecord::new),
  61. FILE_PASS(0x002F, FilePassRecord.class, FilePassRecord::new),
  62. FONT(0x0031, FontRecord.class, FontRecord::new),
  63. CONTINUE(0x003C, ContinueRecord.class, ContinueRecord::new),
  64. WINDOW_ONE(0x003D, WindowOneRecord.class, WindowOneRecord::new),
  65. BACKUP(0x0040, BackupRecord.class, BackupRecord::new),
  66. PANE(0x0041, PaneRecord.class, PaneRecord::new),
  67. CODEPAGE(0x0042, CodepageRecord.class, CodepageRecord::new),
  68. DCON_REF(0x0051, DConRefRecord.class, DConRefRecord::new),
  69. DEFAULT_COL_WIDTH(0x0055, DefaultColWidthRecord.class, DefaultColWidthRecord::new),
  70. CRN_COUNT(0x0059, CRNCountRecord.class, CRNCountRecord::new),
  71. CRN(0x005A, CRNRecord.class, CRNRecord::new),
  72. WRITE_ACCESS(0x005C, WriteAccessRecord.class, WriteAccessRecord::new),
  73. FILE_SHARING(0x005B, FileSharingRecord.class, FileSharingRecord::new),
  74. OBJ(0x005D, ObjRecord.class, ObjRecord::new),
  75. UNCALCED(0x005E, UncalcedRecord.class, UncalcedRecord::new),
  76. SAVE_RECALC(0x005F, SaveRecalcRecord.class, SaveRecalcRecord::new),
  77. OBJECT_PROTECT(0x0063, ObjectProtectRecord.class, ObjectProtectRecord::new),
  78. COLUMN_INFO(0x007D, ColumnInfoRecord.class, ColumnInfoRecord::new),
  79. GUTS(0x0080, GutsRecord.class, GutsRecord::new),
  80. WS_BOOL(0x0081, WSBoolRecord.class, WSBoolRecord::new),
  81. GRIDSET(0x0082, GridsetRecord.class, GridsetRecord::new),
  82. H_CENTER(0x0083, HCenterRecord.class, HCenterRecord::new),
  83. V_CENTER(0x0084, VCenterRecord.class, VCenterRecord::new),
  84. BOUND_SHEET(0x0085, BoundSheetRecord.class, BoundSheetRecord::new),
  85. WRITE_PROTECT(0x0086, WriteProtectRecord.class, WriteProtectRecord::new),
  86. COUNTRY(0X008C, CountryRecord.class, CountryRecord::new),
  87. HIDE_OBJ(0x008D, HideObjRecord.class, HideObjRecord::new),
  88. PALETTE(0x0092, PaletteRecord.class, PaletteRecord::new),
  89. FN_GROUP_COUNT(0x009c, FnGroupCountRecord.class, FnGroupCountRecord::new),
  90. AUTO_FILTER_INFO(0x009D, AutoFilterInfoRecord.class, AutoFilterInfoRecord::new),
  91. SCL(0x00A0, SCLRecord.class, SCLRecord::new, false),
  92. PRINT_SETUP(0x00A1, PrintSetupRecord.class, PrintSetupRecord::new),
  93. VIEW_DEFINITION(0x00B0, ViewDefinitionRecord.class, ViewDefinitionRecord::new),
  94. VIEW_FIELDS(0x00B1, ViewFieldsRecord.class, ViewFieldsRecord::new),
  95. PAGE_ITEM(0x00B6, PageItemRecord.class, PageItemRecord::new),
  96. MUL_BLANK(0x00BE, MulBlankRecord.class, MulBlankRecord::new),
  97. MUL_RK(0x00BD, MulRKRecord.class, MulRKRecord::new),
  98. MMS(0x00C1, MMSRecord.class, MMSRecord::new),
  99. DATA_ITEM(0x00C5, DataItemRecord.class, DataItemRecord::new),
  100. STREAM_ID(0x00D5, StreamIDRecord.class, StreamIDRecord::new),
  101. DB_CELL(0x00D7, DBCellRecord.class, DBCellRecord::new),
  102. BOOK_BOOL(0x00DA, BookBoolRecord.class, BookBoolRecord::new),
  103. SCENARIO_PROTECT(0x00DD, ScenarioProtectRecord.class, ScenarioProtectRecord::new),
  104. EXTENDED_FORMAT(0x00E0, ExtendedFormatRecord.class, ExtendedFormatRecord::new),
  105. INTERFACE_HDR(0x00E1, InterfaceHdrRecord.class, InterfaceHdrRecord::new),
  106. INTERFACE_END(0x00E2, InterfaceEndRecord.class, InterfaceEndRecord::create),
  107. VIEW_SOURCE(0x00E3, ViewSourceRecord.class, ViewSourceRecord::new),
  108. MERGE_CELLS(0x00E5, MergeCellsRecord.class, MergeCellsRecord::new),
  109. DRAWING_GROUP(0x00EB, DrawingGroupRecord.class, DrawingGroupRecord::new),
  110. DRAWING(0x00EC, DrawingRecord.class, DrawingRecord::new),
  111. DRAWING_SELECTION(0x00ED, DrawingSelectionRecord.class, DrawingSelectionRecord::new),
  112. SST(0x00FC, SSTRecord.class, SSTRecord::new),
  113. LABEL_SST(0X00FD, LabelSSTRecord.class, LabelSSTRecord::new),
  114. EXT_SST(0x00FF, ExtSSTRecord.class, ExtSSTRecord::new),
  115. EXTENDED_PIVOT_TABLE_VIEW_FIELDS(0x0100, ExtendedPivotTableViewFieldsRecord.class, ExtendedPivotTableViewFieldsRecord::new),
  116. TAB_ID(0x013D, TabIdRecord.class, TabIdRecord::new),
  117. USE_SEL_FS(0x0160, UseSelFSRecord.class, UseSelFSRecord::new),
  118. DSF(0x0161, DSFRecord.class, DSFRecord::new),
  119. USER_SVIEW_BEGIN(0x01AA, UserSViewBegin.class, UserSViewBegin::new),
  120. USER_SVIEW_END(0x01AB, UserSViewEnd.class, UserSViewEnd::new),
  121. SUP_BOOK(0x01AE, SupBookRecord.class, SupBookRecord::new),
  122. PROTECTION_REV_4(0x01AF, ProtectionRev4Record.class, ProtectionRev4Record::new),
  123. CF_HEADER(0x01B0, CFHeaderRecord.class, CFHeaderRecord::new),
  124. CF_RULE(0x01B1, CFRuleRecord.class, CFRuleRecord::new),
  125. DVAL(0x01B2, DVALRecord.class, DVALRecord::new),
  126. TEXT_OBJECT(0x01B6, TextObjectRecord.class, TextObjectRecord::new),
  127. REFRESH_ALL(0x01B7, RefreshAllRecord.class, RefreshAllRecord::new),
  128. HYPERLINK(0x01B8, HyperlinkRecord.class, HyperlinkRecord::new),
  129. PASSWORD_REV_4(0x01BC, PasswordRev4Record.class, PasswordRev4Record::new),
  130. DV(0x01BE, DVRecord.class, DVRecord::new),
  131. RECALC_ID(0x01C1, RecalcIdRecord.class, RecalcIdRecord::new),
  132. DIMENSIONS(0x0200, DimensionsRecord.class, DimensionsRecord::new),
  133. BLANK(0x0201, BlankRecord.class, BlankRecord::new),
  134. NUMBER(0x0203, NumberRecord.class, NumberRecord::new),
  135. LABEL(0x0204, LabelRecord.class, LabelRecord::new),
  136. BOOL_ERR(0x0205, BoolErrRecord.class, BoolErrRecord::new),
  137. STRING(0x0207, StringRecord.class, StringRecord::new),
  138. ROW(0x0208, RowRecord.class, RowRecord::new),
  139. INDEX(0x020B, IndexRecord.class, IndexRecord::new),
  140. ARRAY(0x0221, ArrayRecord.class, ArrayRecord::new),
  141. DEFAULT_ROW_HEIGHT(0x0225, DefaultRowHeightRecord.class, DefaultRowHeightRecord::new),
  142. TABLE(0x0236, TableRecord.class, TableRecord::new),
  143. WINDOW_TWO(0x023E, WindowTwoRecord.class, WindowTwoRecord::new),
  144. RK(0x027E, RKRecord.class, RKRecord::new),
  145. STYLE(0x0293, StyleRecord.class, StyleRecord::new),
  146. FORMAT(0x041E, FormatRecord.class, FormatRecord::new),
  147. SHARED_FORMULA(0x04BC, SharedFormulaRecord.class, SharedFormulaRecord::new),
  148. BOF(0x0809, BOFRecord.class, BOFRecord::new),
  149. CHART_FRT_INFO(0x0850, ChartFRTInfoRecord.class, ChartFRTInfoRecord::new),
  150. CHART_START_BLOCK(0x0852, ChartStartBlockRecord.class, ChartStartBlockRecord::new),
  151. CHART_END_BLOCK(0x0853, ChartEndBlockRecord.class, ChartEndBlockRecord::new),
  152. CHART_START_OBJECT(0x0854, ChartStartObjectRecord.class, ChartStartObjectRecord::new),
  153. CHART_END_OBJECT(0x0855, ChartEndObjectRecord.class, ChartEndObjectRecord::new),
  154. CAT_LAB(0x0856, CatLabRecord.class, CatLabRecord::new),
  155. FEAT_HDR(0x0867, FeatHdrRecord.class, FeatHdrRecord::new),
  156. FEAT(0x0868, FeatRecord.class, FeatRecord::new),
  157. DATA_LABEL_EXTENSION(0x086A, DataLabelExtensionRecord.class, DataLabelExtensionRecord::new, false),
  158. CF_HEADER_12(0x0879, CFHeader12Record.class, CFHeader12Record::new),
  159. CF_RULE_12(0x087A, CFRule12Record.class, CFRule12Record::new),
  160. TABLE_STYLES(0x088E, TableStylesRecord.class, TableStylesRecord::new),
  161. NAME_COMMENT(0x0894, NameCommentRecord.class, NameCommentRecord::new),
  162. HEADER_FOOTER(0x089C, HeaderFooterRecord.class, HeaderFooterRecord::new),
  163. UNITS(0x1001, UnitsRecord.class, UnitsRecord::new, false),
  164. CHART(0x1002, ChartRecord.class, ChartRecord::new),
  165. SERIES(0x1003, SeriesRecord.class, SeriesRecord::new),
  166. DATA_FORMAT(0x1006, DataFormatRecord.class, DataFormatRecord::new),
  167. LINE_FORMAT(0x1007, LineFormatRecord.class, LineFormatRecord::new, false),
  168. AREA_FORMAT(0x100A, AreaFormatRecord.class, AreaFormatRecord::new, false),
  169. SERIES_LABELS(0x100C, SeriesLabelsRecord.class, SeriesLabelsRecord::new, false),
  170. SERIES_TEXT(0x100D, SeriesTextRecord.class, SeriesTextRecord::new),
  171. CHART_FORMAT(0x1014, ChartFormatRecord.class, ChartFormatRecord::new, false),
  172. LEGEND(0x1015, LegendRecord.class, LegendRecord::new),
  173. SERIES_LIST(0x1016, SeriesListRecord.class, SeriesListRecord::new, false),
  174. BAR(0x1017, BarRecord.class, BarRecord::new, false),
  175. AREA(0x101A, AreaRecord.class, AreaRecord::new),
  176. AXIS(0x101D, AxisRecord.class, AxisRecord::new, false),
  177. TICK(0x101E, TickRecord.class, TickRecord::new, false),
  178. VALUE_RANGE(0x101F, ValueRangeRecord.class, ValueRangeRecord::new),
  179. CATEGORY_SERIES_AXIS(0x1020, CategorySeriesAxisRecord.class, CategorySeriesAxisRecord::new, false),
  180. AXIS_LINE_FORMAT(0x1021, AxisLineFormatRecord.class, AxisLineFormatRecord::new, false),
  181. DEFAULT_DATA_LABEL_TEXT_PROPERTIES(0x1024, DefaultDataLabelTextPropertiesRecord.class, DefaultDataLabelTextPropertiesRecord::new, false),
  182. TEXT(0x1025, TextRecord.class, TextRecord::new, false),
  183. FONT_INDEX(0x1026, FontIndexRecord.class, FontIndexRecord::new, false),
  184. OBJECT_LINK(0x1027, ObjectLinkRecord.class, ObjectLinkRecord::new, false),
  185. FRAME(0x1032, FrameRecord.class, FrameRecord::new, false),
  186. BEGIN(0x1033, BeginRecord.class, BeginRecord::new),
  187. END(0x1034, EndRecord.class, EndRecord::new),
  188. PLOT_AREA(0x1035, PlotAreaRecord.class, PlotAreaRecord::new, false),
  189. AXIS_PARENT(0x1041, AxisParentRecord.class, AxisParentRecord::new, false),
  190. SHEET_PROPERTIES(0x1044, SheetPropertiesRecord.class, SheetPropertiesRecord::new, false),
  191. SERIES_CHART_GROUP_INDEX(0x1045, SeriesChartGroupIndexRecord.class, SeriesChartGroupIndexRecord::new),
  192. AXIS_USED(0x1046, AxisUsedRecord.class, AxisUsedRecord::new, false),
  193. NUMBER_FORMAT_INDEX(0x104E, NumberFormatIndexRecord.class, NumberFormatIndexRecord::new, false),
  194. CHART_TITLE_FORMAT(0x1050, ChartTitleFormatRecord.class, ChartTitleFormatRecord::new),
  195. LINKED_DATA(0x1051, LinkedDataRecord.class, LinkedDataRecord::new),
  196. FONT_BASIS(0x1060, FontBasisRecord.class, FontBasisRecord::new, false),
  197. AXIS_OPTIONS(0x1062, AxisOptionsRecord.class, AxisOptionsRecord::new, false),
  198. DAT(0x1063, DatRecord.class, DatRecord::new, false),
  199. PLOT_GROWTH(0x1064, PlotGrowthRecord.class, PlotGrowthRecord::new, false),
  200. SERIES_INDEX(0x1065, SeriesIndexRecord.class, SeriesIndexRecord::new, false),
  201. // Dummy record
  202. ESCHER_AGGREGATE(9876, EscherAggregate.class, (in) -> new EscherAggregate(true))
  203. ;
  204. @FunctionalInterface
  205. public interface RecordConstructor<T extends Record> {
  206. T apply(RecordInputStream in);
  207. }
  208. private static final Map<Short,HSSFRecordTypes> LOOKUP =
  209. Arrays.stream(values()).collect(Collectors.toMap(HSSFRecordTypes::getSid, Function.identity()));
  210. public final short sid;
  211. public final Class<? extends org.apache.poi.hssf.record.Record> clazz;
  212. public final RecordConstructor<? extends org.apache.poi.hssf.record.Record> recordConstructor;
  213. public final boolean parse;
  214. HSSFRecordTypes(int sid, Class<? extends org.apache.poi.hssf.record.Record> clazz, RecordConstructor<? extends org.apache.poi.hssf.record.Record> recordConstructor) {
  215. this(sid, clazz, recordConstructor,true);
  216. }
  217. HSSFRecordTypes(int sid, Class<? extends org.apache.poi.hssf.record.Record> clazz, RecordConstructor<? extends org.apache.poi.hssf.record.Record> recordConstructor, boolean parse) {
  218. this.sid = (short)sid;
  219. this.clazz = clazz;
  220. this.recordConstructor = recordConstructor;
  221. this.parse = parse;
  222. }
  223. public static HSSFRecordTypes forSID(int sid) {
  224. return LOOKUP.getOrDefault((short)sid, UNKNOWN);
  225. }
  226. public short getSid() {
  227. return sid;
  228. }
  229. public Class<? extends Record> getClazz() {
  230. return clazz;
  231. }
  232. public RecordConstructor<? extends org.apache.poi.hssf.record.Record> getRecordConstructor() {
  233. return recordConstructor;
  234. }
  235. public boolean isParseable() {
  236. return parse;
  237. }
  238. }