Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MulRKRecord.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.hssf.util.RKUtil;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. import org.apache.poi.util.RecordFormatException;
  23. /**
  24. * Used to store multiple RK numbers on a row. 1 MulRk = Multiple Cell values.
  25. * HSSF just converts this into multiple NUMBER records. READ-ONLY SUPPORT!
  26. *
  27. * @since 2.0-pre
  28. */
  29. public final class MulRKRecord extends StandardRecord {
  30. public static final short sid = 0x00BD;
  31. private final int field_1_row;
  32. private final short field_2_first_col;
  33. private final RkRec[] field_3_rks;
  34. private final short field_4_last_col;
  35. public int getRow() {
  36. return field_1_row;
  37. }
  38. /**
  39. * starting column (first cell this holds in the row)
  40. * @return first column number
  41. */
  42. public short getFirstColumn() {
  43. return field_2_first_col;
  44. }
  45. /**
  46. * ending column (last cell this holds in the row)
  47. * @return first column number
  48. */
  49. public short getLastColumn() {
  50. return field_4_last_col;
  51. }
  52. /**
  53. * get the number of columns this contains (last-first +1)
  54. * @return number of columns (last - first +1)
  55. */
  56. public int getNumColumns() {
  57. return field_4_last_col - field_2_first_col + 1;
  58. }
  59. /**
  60. * returns the xf index for column (coffset = column - field_2_first_col)
  61. *
  62. * @param coffset the coffset = column - field_2_first_col
  63. *
  64. * @return the XF index for the column
  65. */
  66. public short getXFAt(int coffset) {
  67. return field_3_rks[coffset].xf;
  68. }
  69. /**
  70. * returns the rk number for column (coffset = column - field_2_first_col)
  71. *
  72. * @param coffset the coffset = column - field_2_first_col
  73. *
  74. * @return the value (decoded into a double)
  75. */
  76. public double getRKNumberAt(int coffset) {
  77. return RKUtil.decodeNumber(field_3_rks[coffset].rk);
  78. }
  79. /**
  80. * @param in the RecordInputstream to read the record from
  81. */
  82. public MulRKRecord(RecordInputStream in) {
  83. field_1_row = in.readUShort();
  84. field_2_first_col = in.readShort();
  85. field_3_rks = RkRec.parseRKs(in);
  86. field_4_last_col = in.readShort();
  87. }
  88. @Override
  89. public short getSid()
  90. {
  91. return sid;
  92. }
  93. @Override
  94. public void serialize(LittleEndianOutput out) {
  95. throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
  96. }
  97. @Override
  98. protected int getDataSize() {
  99. throw new RecordFormatException( "Sorry, you can't serialize MulRK in this release");
  100. }
  101. private static final class RkRec implements GenericRecord {
  102. public static final int ENCODED_SIZE = 6;
  103. public final short xf;
  104. public final int rk;
  105. private RkRec(RecordInputStream in) {
  106. xf = in.readShort();
  107. rk = in.readInt();
  108. }
  109. public static RkRec[] parseRKs(RecordInputStream in) {
  110. int nItems = (in.remaining()-2) / ENCODED_SIZE;
  111. RkRec[] retval = new RkRec[nItems];
  112. for (int i=0; i<nItems; i++) {
  113. retval[i] = new RkRec(in);
  114. }
  115. return retval;
  116. }
  117. @Override
  118. public Map<String, Supplier<?>> getGenericProperties() {
  119. return GenericRecordUtil.getGenericProperties(
  120. "xf", () -> xf,
  121. "rk", () -> rk
  122. );
  123. }
  124. }
  125. @Override
  126. public MulRKRecord copy() {
  127. // immutable - so OK to return this
  128. return this;
  129. }
  130. @Override
  131. public HSSFRecordTypes getGenericRecordType() {
  132. return HSSFRecordTypes.MUL_RK;
  133. }
  134. @Override
  135. public Map<String, Supplier<?>> getGenericProperties() {
  136. return GenericRecordUtil.getGenericProperties(
  137. "row", this::getRow,
  138. "firstColumn", this::getFirstColumn,
  139. "lastColumn", this::getLastColumn,
  140. "rk", () -> field_3_rks
  141. );
  142. }
  143. }