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.

TableRecord.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.hssf.record;
  16. import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
  17. import java.util.Map;
  18. import java.util.function.Supplier;
  19. import org.apache.poi.hssf.util.CellRangeAddress8Bit;
  20. import org.apache.poi.ss.formula.ptg.TblPtg;
  21. import org.apache.poi.ss.util.CellReference;
  22. import org.apache.poi.util.BitField;
  23. import org.apache.poi.util.BitFieldFactory;
  24. import org.apache.poi.util.GenericRecordUtil;
  25. import org.apache.poi.util.LittleEndianOutput;
  26. /**
  27. * The record specifies a data table.<p>
  28. * This record is preceded by a single Formula record that defines the first cell in the data table,
  29. * which should only contain a single {@link TblPtg Ptg}.
  30. */
  31. public final class TableRecord extends SharedValueRecordBase {
  32. public static final short sid = 0x0236;
  33. private static final BitField alwaysCalc = BitFieldFactory.getInstance(0x0001);
  34. private static final BitField calcOnOpen = BitFieldFactory.getInstance(0x0002);
  35. private static final BitField rowOrColInpCell = BitFieldFactory.getInstance(0x0004);
  36. private static final BitField oneOrTwoVar = BitFieldFactory.getInstance(0x0008);
  37. private static final BitField rowDeleted = BitFieldFactory.getInstance(0x0010);
  38. private static final BitField colDeleted = BitFieldFactory.getInstance(0x0020);
  39. private int field_5_flags;
  40. private int field_6_res;
  41. private int field_7_rowInputRow;
  42. private int field_8_colInputRow;
  43. private int field_9_rowInputCol;
  44. private int field_10_colInputCol;
  45. public TableRecord(TableRecord other) {
  46. super(other);
  47. field_5_flags = other.field_5_flags;
  48. field_6_res = other.field_6_res;
  49. field_7_rowInputRow = other.field_7_rowInputRow;
  50. field_8_colInputRow = other.field_8_colInputRow;
  51. field_9_rowInputCol = other.field_9_rowInputCol;
  52. field_10_colInputCol = other.field_10_colInputCol;
  53. }
  54. public TableRecord(RecordInputStream in) {
  55. super(in);
  56. field_5_flags = in.readByte();
  57. field_6_res = in.readByte();
  58. field_7_rowInputRow = in.readShort();
  59. field_8_colInputRow = in.readShort();
  60. field_9_rowInputCol = in.readShort();
  61. field_10_colInputCol = in.readShort();
  62. }
  63. public TableRecord(CellRangeAddress8Bit range) {
  64. super(range);
  65. field_6_res = 0;
  66. }
  67. public int getFlags() {
  68. return field_5_flags;
  69. }
  70. public void setFlags(int flags) {
  71. field_5_flags = flags;
  72. }
  73. public int getRowInputRow() {
  74. return field_7_rowInputRow;
  75. }
  76. public void setRowInputRow(int rowInputRow) {
  77. field_7_rowInputRow = rowInputRow;
  78. }
  79. public int getColInputRow() {
  80. return field_8_colInputRow;
  81. }
  82. public void setColInputRow(int colInputRow) {
  83. field_8_colInputRow = colInputRow;
  84. }
  85. public int getRowInputCol() {
  86. return field_9_rowInputCol;
  87. }
  88. public void setRowInputCol(int rowInputCol) {
  89. field_9_rowInputCol = rowInputCol;
  90. }
  91. public int getColInputCol() {
  92. return field_10_colInputCol;
  93. }
  94. public void setColInputCol(int colInputCol) {
  95. field_10_colInputCol = colInputCol;
  96. }
  97. public boolean isAlwaysCalc() {
  98. return alwaysCalc.isSet(field_5_flags);
  99. }
  100. public void setAlwaysCalc(boolean flag) {
  101. field_5_flags = alwaysCalc.setBoolean(field_5_flags, flag);
  102. }
  103. public boolean isRowOrColInpCell() {
  104. return rowOrColInpCell.isSet(field_5_flags);
  105. }
  106. public void setRowOrColInpCell(boolean flag) {
  107. field_5_flags = rowOrColInpCell.setBoolean(field_5_flags, flag);
  108. }
  109. public boolean isOneNotTwoVar() {
  110. return oneOrTwoVar.isSet(field_5_flags);
  111. }
  112. public void setOneNotTwoVar(boolean flag) {
  113. field_5_flags = oneOrTwoVar.setBoolean(field_5_flags, flag);
  114. }
  115. public boolean isColDeleted() {
  116. return colDeleted.isSet(field_5_flags);
  117. }
  118. public void setColDeleted(boolean flag) {
  119. field_5_flags = colDeleted.setBoolean(field_5_flags, flag);
  120. }
  121. public boolean isRowDeleted() {
  122. return rowDeleted.isSet(field_5_flags);
  123. }
  124. public void setRowDeleted(boolean flag) {
  125. field_5_flags = rowDeleted.setBoolean(field_5_flags, flag);
  126. }
  127. public short getSid() {
  128. return sid;
  129. }
  130. protected int getExtraDataSize() {
  131. return
  132. 2 // 2 byte fields
  133. + 8; // 4 short fields
  134. }
  135. protected void serializeExtraData(LittleEndianOutput out) {
  136. out.writeByte(field_5_flags);
  137. out.writeByte(field_6_res);
  138. out.writeShort(field_7_rowInputRow);
  139. out.writeShort(field_8_colInputRow);
  140. out.writeShort(field_9_rowInputCol);
  141. out.writeShort(field_10_colInputCol);
  142. }
  143. @Override
  144. public TableRecord copy() {
  145. return new TableRecord(this);
  146. }
  147. private static CellReference cr(int rowIx, int colIxAndFlags) {
  148. int colIx = colIxAndFlags & 0x00FF;
  149. boolean isRowAbs = (colIxAndFlags & 0x8000) == 0;
  150. boolean isColAbs = (colIxAndFlags & 0x4000) == 0;
  151. return new CellReference(rowIx, colIx, isRowAbs, isColAbs);
  152. }
  153. @Override
  154. public HSSFRecordTypes getGenericRecordType() {
  155. return HSSFRecordTypes.TABLE;
  156. }
  157. @Override
  158. public Map<String, Supplier<?>> getGenericProperties() {
  159. return GenericRecordUtil.getGenericProperties(
  160. "range", this::getRange,
  161. "flags", getBitsAsString(this::getFlags,
  162. new BitField[]{alwaysCalc, calcOnOpen, rowOrColInpCell, oneOrTwoVar, rowDeleted, colDeleted},
  163. new String[]{"ALWAYS_CALC","CALC_ON_OPEN","ROW_OR_COL_INP_CELL","ONE_OR_TWO_VAR","ROW_DELETED","COL_DELETED"}),
  164. "reserved", () -> field_6_res,
  165. "rowInput", () -> cr(field_7_rowInputRow, field_8_colInputRow),
  166. "colInput", () -> cr(field_9_rowInputCol, field_10_colInputCol)
  167. );
  168. }
  169. }