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.

OldCellRecord.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.common.usermodel.GenericRecord;
  19. import org.apache.poi.util.GenericRecordJsonWriter;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. /**
  22. * Base class for all old (Biff 2 - Biff 4) cell value records
  23. * (implementors of {@link CellValueRecordInterface}).
  24. * Subclasses are expected to manage the cell data values (of various types).
  25. */
  26. public abstract class OldCellRecord implements GenericRecord {
  27. private final short sid;
  28. private final boolean isBiff2;
  29. private final int field_1_row;
  30. private final short field_2_column;
  31. private int field_3_cell_attrs; // Biff 2
  32. private short field_3_xf_index; // Biff 3+
  33. protected OldCellRecord(RecordInputStream in, boolean isBiff2) {
  34. this.sid = in.getSid();
  35. this.isBiff2 = isBiff2;
  36. field_1_row = in.readUShort();
  37. field_2_column = in.readShort();
  38. if (isBiff2) {
  39. field_3_cell_attrs = in.readUShort() << 8;
  40. field_3_cell_attrs += in.readUByte();
  41. } else {
  42. field_3_xf_index = in.readShort();
  43. }
  44. }
  45. public final int getRow() {
  46. return field_1_row;
  47. }
  48. public final short getColumn() {
  49. return field_2_column;
  50. }
  51. /**
  52. * get the index to the ExtendedFormat, for non-Biff2
  53. *
  54. * @see org.apache.poi.hssf.record.ExtendedFormatRecord
  55. * @return index to the XF record
  56. */
  57. public final short getXFIndex() {
  58. return field_3_xf_index;
  59. }
  60. public int getCellAttrs()
  61. {
  62. return field_3_cell_attrs;
  63. }
  64. /**
  65. * Is this a Biff2 record, or newer?
  66. *
  67. * @return true, if this is a Biff2 record or newer
  68. */
  69. public boolean isBiff2() {
  70. return isBiff2;
  71. }
  72. public short getSid() {
  73. return sid;
  74. }
  75. @Override
  76. public Map<String, Supplier<?>> getGenericProperties() {
  77. return GenericRecordUtil.getGenericProperties(
  78. "row", this::getRow,
  79. "column", this::getColumn,
  80. "biff2", this::isBiff2,
  81. "biff2CellAttrs", this::getCellAttrs,
  82. "xfIndex", this::getXFIndex
  83. );
  84. }
  85. @Override
  86. public final String toString() {
  87. return GenericRecordJsonWriter.marshal(this);
  88. }
  89. }