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.

MulBlankRecord.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.util.GenericRecordUtil;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Represents a set of columns in a row with no value but with styling.
  22. *
  23. * @see BlankRecord
  24. */
  25. public final class MulBlankRecord extends StandardRecord {
  26. public static final short sid = 0x00BE;
  27. private final int _row;
  28. private final int _firstCol;
  29. private final short[] _xfs;
  30. private final int _lastCol;
  31. public MulBlankRecord(int row, int firstCol, short[] xfs) {
  32. _row = row;
  33. _firstCol = firstCol;
  34. _xfs = xfs;
  35. _lastCol = firstCol + xfs.length - 1;
  36. }
  37. /**
  38. * @return the row number of the cells this represents
  39. */
  40. public int getRow() {
  41. return _row;
  42. }
  43. /**
  44. * @return starting column (first cell this holds in the row). Zero based
  45. */
  46. public int getFirstColumn() {
  47. return _firstCol;
  48. }
  49. /**
  50. * @return ending column (last cell this holds in the row). Zero based
  51. */
  52. public int getLastColumn() {
  53. return _lastCol;
  54. }
  55. /**
  56. * get the number of columns this contains (last-first +1)
  57. * @return number of columns (last - first +1)
  58. */
  59. public int getNumColumns() {
  60. return _lastCol - _firstCol + 1;
  61. }
  62. /**
  63. * returns the xf index for column (coffset = column - field_2_first_col)
  64. * @param coffset the column (coffset = column - field_2_first_col)
  65. * @return the XF index for the column
  66. */
  67. public short getXFAt(int coffset) {
  68. return _xfs[coffset];
  69. }
  70. /**
  71. * @param in the RecordInputstream to read the record from
  72. */
  73. public MulBlankRecord(RecordInputStream in) {
  74. _row = in.readUShort();
  75. _firstCol = in.readShort();
  76. _xfs = parseXFs(in);
  77. _lastCol = in.readShort();
  78. }
  79. private static short [] parseXFs(RecordInputStream in) {
  80. short[] retval = new short[(in.remaining() - 2) / 2];
  81. for (int idx = 0; idx < retval.length;idx++) {
  82. retval[idx] = in.readShort();
  83. }
  84. return retval;
  85. }
  86. public short getSid() {
  87. return sid;
  88. }
  89. public void serialize(LittleEndianOutput out) {
  90. out.writeShort(_row);
  91. out.writeShort(_firstCol);
  92. for (short xf : _xfs) {
  93. out.writeShort(xf);
  94. }
  95. out.writeShort(_lastCol);
  96. }
  97. protected int getDataSize() {
  98. // 3 short fields + array of shorts
  99. return 6 + _xfs.length * 2;
  100. }
  101. @Override
  102. public MulBlankRecord copy() {
  103. // immutable - so OK to return this
  104. return this;
  105. }
  106. @Override
  107. public HSSFRecordTypes getGenericRecordType() {
  108. return HSSFRecordTypes.MUL_BLANK;
  109. }
  110. @Override
  111. public Map<String, Supplier<?>> getGenericProperties() {
  112. return GenericRecordUtil.getGenericProperties(
  113. "row", this::getRow,
  114. "firstColumn", this::getFirstColumn,
  115. "lastColumn", this::getLastColumn,
  116. "xf", () -> _xfs
  117. );
  118. }
  119. }