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.

MulBlankRecord.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 org.apache.poi.util.LittleEndianOutput;
  17. /**
  18. * Title: Multiple Blank cell record(0x00BE) <P/>
  19. * Description: Represents a set of columns in a row with no value but with styling.
  20. * <p/>
  21. * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P/>
  22. * @author Andrew C. Oliver (acoliver at apache dot org)
  23. * @author Glen Stampoultzis (glens at apache.org)
  24. * @see BlankRecord
  25. */
  26. public final class MulBlankRecord extends StandardRecord {
  27. public final static short sid = 0x00BE;
  28. private final int _row;
  29. private final int _firstCol;
  30. private final short[] _xfs;
  31. private final int _lastCol;
  32. public MulBlankRecord(int row, int firstCol, short[] xfs) {
  33. _row = row;
  34. _firstCol = firstCol;
  35. _xfs = xfs;
  36. _lastCol = firstCol + xfs.length - 1;
  37. }
  38. /**
  39. * @return the row number of the cells this represents
  40. */
  41. public int getRow() {
  42. return _row;
  43. }
  44. /**
  45. * @return starting column (first cell this holds in the row). Zero based
  46. */
  47. public int getFirstColumn() {
  48. return _firstCol;
  49. }
  50. /**
  51. * @return ending column (last cell this holds in the row). Zero based
  52. */
  53. public int getLastColumn() {
  54. return _lastCol;
  55. }
  56. /**
  57. * get the number of columns this contains (last-first +1)
  58. * @return number of columns (last - first +1)
  59. */
  60. public int getNumColumns() {
  61. return _lastCol - _firstCol + 1;
  62. }
  63. /**
  64. * returns the xf index for column (coffset = column - field_2_first_col)
  65. * @param coffset the column (coffset = column - field_2_first_col)
  66. * @return the XF index for the column
  67. */
  68. public short getXFAt(int coffset) {
  69. return _xfs[coffset];
  70. }
  71. /**
  72. * @param in the RecordInputstream to read the record from
  73. */
  74. public MulBlankRecord(RecordInputStream in) {
  75. _row = in.readUShort();
  76. _firstCol = in.readShort();
  77. _xfs = parseXFs(in);
  78. _lastCol = in.readShort();
  79. }
  80. private static short [] parseXFs(RecordInputStream in) {
  81. short[] retval = new short[(in.remaining() - 2) / 2];
  82. for (int idx = 0; idx < retval.length;idx++) {
  83. retval[idx] = in.readShort();
  84. }
  85. return retval;
  86. }
  87. public String toString() {
  88. StringBuffer buffer = new StringBuffer();
  89. buffer.append("[MULBLANK]\n");
  90. buffer.append("row = ").append(Integer.toHexString(getRow())).append("\n");
  91. buffer.append("firstcol = ").append(Integer.toHexString(getFirstColumn())).append("\n");
  92. buffer.append(" lastcol = ").append(Integer.toHexString(_lastCol)).append("\n");
  93. for (int k = 0; k < getNumColumns(); k++) {
  94. buffer.append("xf").append(k).append(" = ").append(
  95. Integer.toHexString(getXFAt(k))).append("\n");
  96. }
  97. buffer.append("[/MULBLANK]\n");
  98. return buffer.toString();
  99. }
  100. public short getSid() {
  101. return sid;
  102. }
  103. public void serialize(LittleEndianOutput out) {
  104. out.writeShort(_row);
  105. out.writeShort(_firstCol);
  106. int nItems = _xfs.length;
  107. for (int i = 0; i < nItems; i++) {
  108. out.writeShort(_xfs[i]);
  109. }
  110. out.writeShort(_lastCol);
  111. }
  112. protected int getDataSize() {
  113. // 3 short fields + array of shorts
  114. return 6 + _xfs.length * 2;
  115. }
  116. @Override
  117. public Object clone() {
  118. // immutable - so OK to return this
  119. return this;
  120. }
  121. }