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.

DimensionsRecord.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. import org.apache.poi.util.POILogFactory;
  21. import org.apache.poi.util.POILogger;
  22. /**
  23. * Provides the minumum and maximum bounds of a sheet.
  24. *
  25. * @version 2.0-pre
  26. */
  27. public final class DimensionsRecord extends StandardRecord {
  28. private static final POILogger LOG = POILogFactory.getLogger(DimensionsRecord.class);
  29. public static final short sid = 0x200;
  30. private int field_1_first_row;
  31. private int field_2_last_row; // plus 1
  32. private short field_3_first_col;
  33. private short field_4_last_col;
  34. private short field_5_zero; // must be 0 (reserved)
  35. public DimensionsRecord() {}
  36. public DimensionsRecord(DimensionsRecord other) {
  37. super(other);
  38. field_1_first_row = other.field_1_first_row;
  39. field_2_last_row = other.field_2_last_row;
  40. field_3_first_col = other.field_3_first_col;
  41. field_4_last_col = other.field_4_last_col;
  42. field_5_zero = other.field_5_zero;
  43. }
  44. public DimensionsRecord(RecordInputStream in) {
  45. field_1_first_row = in.readInt();
  46. field_2_last_row = in.readInt();
  47. field_3_first_col = in.readShort();
  48. field_4_last_col = in.readShort();
  49. field_5_zero = in.readShort();
  50. //POI-61045 -- in practice, there can be an extra 2 bytes
  51. if (in.available() == 2) {
  52. LOG.log(POILogger.INFO, "DimensionsRecord has extra 2 bytes.");
  53. in.readShort();
  54. }
  55. }
  56. /**
  57. * set the first row number for the sheet
  58. * @param row - first row on the sheet
  59. */
  60. public void setFirstRow(int row)
  61. {
  62. field_1_first_row = row;
  63. }
  64. /**
  65. * set the last row number for the sheet
  66. * @param row - last row on the sheet
  67. */
  68. public void setLastRow(int row)
  69. {
  70. field_2_last_row = row;
  71. }
  72. /**
  73. * set the first column number for the sheet
  74. * @param col first column on the sheet
  75. */
  76. public void setFirstCol(short col)
  77. {
  78. field_3_first_col = col;
  79. }
  80. /**
  81. * set the last col number for the sheet
  82. * @param col last column on the sheet
  83. */
  84. public void setLastCol(short col)
  85. {
  86. field_4_last_col = col;
  87. }
  88. /**
  89. * get the first row number for the sheet
  90. * @return row - first row on the sheet
  91. */
  92. public int getFirstRow()
  93. {
  94. return field_1_first_row;
  95. }
  96. /**
  97. * get the last row number for the sheet
  98. * @return row - last row on the sheet
  99. */
  100. public int getLastRow()
  101. {
  102. return field_2_last_row;
  103. }
  104. /**
  105. * get the first column number for the sheet
  106. * @return column - first column on the sheet
  107. */
  108. public short getFirstCol()
  109. {
  110. return field_3_first_col;
  111. }
  112. /**
  113. * get the last col number for the sheet
  114. * @return column - last column on the sheet
  115. */
  116. public short getLastCol()
  117. {
  118. return field_4_last_col;
  119. }
  120. public void serialize(LittleEndianOutput out) {
  121. out.writeInt(getFirstRow());
  122. out.writeInt(getLastRow());
  123. out.writeShort(getFirstCol());
  124. out.writeShort(getLastCol());
  125. out.writeShort(( short ) 0);
  126. }
  127. protected int getDataSize() {
  128. return 14;
  129. }
  130. public short getSid()
  131. {
  132. return sid;
  133. }
  134. @Override
  135. public DimensionsRecord copy() {
  136. return new DimensionsRecord(this);
  137. }
  138. @Override
  139. public HSSFRecordTypes getGenericRecordType() {
  140. return HSSFRecordTypes.DIMENSIONS;
  141. }
  142. @Override
  143. public Map<String, Supplier<?>> getGenericProperties() {
  144. return GenericRecordUtil.getGenericProperties(
  145. "firstRow", this::getFirstRow,
  146. "lastRow", this::getLastRow,
  147. "firstColumn", this::getFirstCol,
  148. "lastColumn", this::getLastCol,
  149. "zero", () -> field_5_zero
  150. );
  151. }
  152. }