Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

CellRangeAddress8Bit.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.util;
  16. import org.apache.poi.ss.util.CellRangeAddressBase;
  17. import org.apache.poi.util.LittleEndianByteArrayOutputStream;
  18. import org.apache.poi.util.LittleEndianInput;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/>
  22. *
  23. * Like {@link CellRangeAddress} except column fields are 8-bit.
  24. */
  25. public final class CellRangeAddress8Bit extends CellRangeAddressBase {
  26. public static final int ENCODED_SIZE = 6;
  27. public CellRangeAddress8Bit(int firstRow, int lastRow, int firstCol, int lastCol) {
  28. super(firstRow, lastRow, firstCol, lastCol);
  29. }
  30. public CellRangeAddress8Bit(LittleEndianInput in) {
  31. super(readUShortAndCheck(in), in.readUShort(), in.readUByte(), in.readUByte());
  32. }
  33. private static int readUShortAndCheck(LittleEndianInput in) {
  34. if (in.available() < ENCODED_SIZE) {
  35. // Ran out of data
  36. throw new RuntimeException("Ran out of data reading CellRangeAddress");
  37. }
  38. return in.readUShort();
  39. }
  40. public void serialize(LittleEndianOutput out) {
  41. out.writeShort(getFirstRow());
  42. out.writeShort(getLastRow());
  43. out.writeByte(getFirstColumn());
  44. out.writeByte(getLastColumn());
  45. }
  46. public CellRangeAddress8Bit copy() {
  47. return new CellRangeAddress8Bit(getFirstRow(), getLastRow(), getFirstColumn(), getLastColumn());
  48. }
  49. public static int getEncodedSize(int numberOfItems) {
  50. return numberOfItems * ENCODED_SIZE;
  51. }
  52. }