Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

OldSheetRecord.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.io.IOException;
  17. import java.util.Map;
  18. import java.util.function.Supplier;
  19. import org.apache.poi.common.usermodel.GenericRecord;
  20. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  21. import org.apache.poi.util.GenericRecordJsonWriter;
  22. import org.apache.poi.util.GenericRecordUtil;
  23. import org.apache.poi.util.IOUtils;
  24. import org.apache.poi.util.RecordFormatException;
  25. /**
  26. * Title: Bound Sheet Record (aka BundleSheet) (0x0085) for BIFF 5<P>
  27. * Description: Defines a sheet within a workbook. Basically stores the sheet name
  28. * and tells where the Beginning of file record is within the HSSF
  29. * file.
  30. */
  31. public final class OldSheetRecord implements GenericRecord {
  32. public static final short sid = 0x0085;
  33. private final int field_1_position_of_BOF;
  34. private final int field_2_visibility;
  35. private final int field_3_type;
  36. private final byte[] field_5_sheetname;
  37. private CodepageRecord codepage;
  38. public OldSheetRecord(RecordInputStream in) {
  39. field_1_position_of_BOF = in.readInt();
  40. field_2_visibility = in.readUByte();
  41. field_3_type = in.readUByte();
  42. int field_4_sheetname_length = in.readUByte();
  43. if (field_4_sheetname_length > 0) {
  44. in.mark(1);
  45. byte b = in.readByte();
  46. // if the sheet name starts with a 0, we need to skip one byte, otherwise the following records will
  47. // fail with a LeftOverDataException
  48. if (b != 0) {
  49. try {
  50. in.reset();
  51. } catch (IOException e) {
  52. throw new RecordFormatException(e);
  53. }
  54. }
  55. }
  56. field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, HSSFWorkbook.getMaxRecordLength());
  57. in.read(field_5_sheetname, 0, field_4_sheetname_length);
  58. }
  59. public void setCodePage(CodepageRecord codepage) {
  60. this.codepage = codepage;
  61. }
  62. public short getSid() {
  63. return sid;
  64. }
  65. /**
  66. * get the offset in bytes of the Beginning of File Marker within the HSSF Stream part of the POIFS file
  67. *
  68. * @return offset in bytes
  69. */
  70. public int getPositionOfBof() {
  71. return field_1_position_of_BOF;
  72. }
  73. /**
  74. * get the sheetname for this sheet. (this appears in the tabs at the bottom)
  75. * @return sheetname the name of the sheet
  76. */
  77. public String getSheetname() {
  78. return OldStringRecord.getString(field_5_sheetname, codepage);
  79. }
  80. @Override
  81. public HSSFRecordTypes getGenericRecordType() {
  82. return HSSFRecordTypes.BOUND_SHEET;
  83. }
  84. @Override
  85. public Map<String, Supplier<?>> getGenericProperties() {
  86. return GenericRecordUtil.getGenericProperties(
  87. "bof", this::getPositionOfBof,
  88. "visibility", () -> field_2_visibility,
  89. "type", () -> field_3_type,
  90. "sheetName", this::getSheetname
  91. );
  92. }
  93. public String toString() {
  94. return GenericRecordJsonWriter.marshal(this);
  95. }
  96. }