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.

RKRecord.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.hssf.util.RKUtil;
  17. import org.apache.poi.util.LittleEndianOutput;
  18. /**
  19. * Title: RK Record (0x027E)<p/>
  20. * Description: An internal 32 bit number with the two most significant bits
  21. * storing the type. This is part of a bizarre scheme to save disk
  22. * space and memory (gee look at all the other whole records that
  23. * are in the file just "cause"..,far better to waste processor
  24. * cycles on this then leave on of those "valuable" records out).<p/>
  25. * We support this in READ-ONLY mode. HSSF converts these to NUMBER records<p/>
  26. *
  27. *
  28. *
  29. * REFERENCE: PG 376 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  30. * @author Andrew C. Oliver (acoliver at apache dot org)
  31. * @author Jason Height (jheight at chariot dot net dot au)
  32. * @see org.apache.poi.hssf.record.NumberRecord
  33. */
  34. public final class RKRecord extends CellRecord {
  35. public final static short sid = 0x027E;
  36. public final static short RK_IEEE_NUMBER = 0;
  37. public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
  38. public final static short RK_INTEGER = 2;
  39. public final static short RK_INTEGER_TIMES_100 = 3;
  40. private int field_4_rk_number;
  41. private RKRecord() {
  42. // fields uninitialised
  43. }
  44. public RKRecord(RecordInputStream in) {
  45. super(in);
  46. field_4_rk_number = in.readInt();
  47. }
  48. /**
  49. * Extract the value of the number
  50. * <P>
  51. * The mechanism for determining the value is dependent on the two
  52. * low order bits of the raw number. If bit 1 is set, the number
  53. * is an integer and can be cast directly as a double, otherwise,
  54. * it's apparently the exponent and mantissa of a double (and the
  55. * remaining low-order bits of the double's mantissa are 0's).
  56. * <P>
  57. * If bit 0 is set, the result of the conversion to a double is
  58. * divided by 100; otherwise, the value is left alone.
  59. * <P>
  60. * [insert picture of Screwy Squirrel in full Napoleonic regalia]
  61. *
  62. * @return the value as a proper double (hey, it <B>could</B>
  63. * happen)
  64. */
  65. public double getRKNumber() {
  66. return RKUtil.decodeNumber(field_4_rk_number);
  67. }
  68. @Override
  69. protected String getRecordName() {
  70. return "RK";
  71. }
  72. @Override
  73. protected void appendValueText(StringBuilder sb) {
  74. sb.append(" .value= ").append(getRKNumber());
  75. }
  76. @Override
  77. protected void serializeValue(LittleEndianOutput out) {
  78. out.writeInt(field_4_rk_number);
  79. }
  80. @Override
  81. protected int getValueDataSize() {
  82. return 4;
  83. }
  84. public short getSid() {
  85. return sid;
  86. }
  87. public Object clone() {
  88. RKRecord rec = new RKRecord();
  89. copyBaseFields(rec);
  90. rec.field_4_rk_number = field_4_rk_number;
  91. return rec;
  92. }
  93. }