選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ArrayRecord.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.ss.formula.ptg.Ptg;
  17. import org.apache.poi.hssf.util.CellRangeAddress8Bit;
  18. import org.apache.poi.ss.formula.Formula;
  19. import org.apache.poi.util.HexDump;
  20. import org.apache.poi.util.LittleEndianOutput;
  21. /**
  22. * ARRAY (0x0221)<p/>
  23. *
  24. * Treated in a similar way to SharedFormulaRecord
  25. *
  26. * @author Josh Micich
  27. */
  28. public final class ArrayRecord extends SharedValueRecordBase {
  29. public final static short sid = 0x0221;
  30. private static final int OPT_ALWAYS_RECALCULATE = 0x0001;
  31. private static final int OPT_CALCULATE_ON_OPEN = 0x0002;
  32. private int _options;
  33. private int _field3notUsed;
  34. private Formula _formula;
  35. public ArrayRecord(RecordInputStream in) {
  36. super(in);
  37. _options = in.readUShort();
  38. _field3notUsed = in.readInt();
  39. int formulaTokenLen = in.readUShort();
  40. int totalFormulaLen = in.available();
  41. _formula = Formula.read(formulaTokenLen, in, totalFormulaLen);
  42. }
  43. public ArrayRecord(Formula formula, CellRangeAddress8Bit range) {
  44. super(range);
  45. _options = 0; //YK: Excel 2007 leaves this field unset
  46. _field3notUsed = 0;
  47. _formula = formula;
  48. }
  49. public boolean isAlwaysRecalculate() {
  50. return (_options & OPT_ALWAYS_RECALCULATE) != 0;
  51. }
  52. public boolean isCalculateOnOpen() {
  53. return (_options & OPT_CALCULATE_ON_OPEN) != 0;
  54. }
  55. public Ptg[] getFormulaTokens() {
  56. return _formula.getTokens();
  57. }
  58. protected int getExtraDataSize() {
  59. return 2 + 4 + _formula.getEncodedSize();
  60. }
  61. protected void serializeExtraData(LittleEndianOutput out) {
  62. out.writeShort(_options);
  63. out.writeInt(_field3notUsed);
  64. _formula.serialize(out);
  65. }
  66. public short getSid() {
  67. return sid;
  68. }
  69. public String toString() {
  70. StringBuffer sb = new StringBuffer();
  71. sb.append(getClass().getName()).append(" [ARRAY]\n");
  72. sb.append(" range=").append(getRange().toString()).append("\n");
  73. sb.append(" options=").append(HexDump.shortToHex(_options)).append("\n");
  74. sb.append(" notUsed=").append(HexDump.intToHex(_field3notUsed)).append("\n");
  75. sb.append(" formula:").append("\n");
  76. Ptg[] ptgs = _formula.getTokens();
  77. for (int i = 0; i < ptgs.length; i++) {
  78. Ptg ptg = ptgs[i];
  79. sb.append(ptg.toString()).append(ptg.getRVAType()).append("\n");
  80. }
  81. sb.append("]");
  82. return sb.toString();
  83. }
  84. public Object clone() {
  85. ArrayRecord rec = new ArrayRecord(_formula.copy(), getRange());
  86. // they both seem unused, but clone them nevertheless to have an exact copy
  87. rec._options = _options;
  88. rec._field3notUsed = _field3notUsed;
  89. return rec;
  90. }
  91. }