poi/src/java/org/apache/poi/hssf/record/RKRecord.java

174 lines
5.6 KiB
Java

/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.hssf.util.RKUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: RK Record (0x027E)<p/>
* Description: An internal 32 bit number with the two most significant bits
* storing the type. This is part of a bizarre scheme to save disk
* space and memory (gee look at all the other whole records that
* are in the file just "cause"..,far better to waste processor
* cycles on this then leave on of those "valuable" records out).<p/>
* We support this in READ-ONLY mode. HSSF converts these to NUMBER records<p/>
*
*
*
* REFERENCE: PG 376 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
* @see org.apache.poi.hssf.record.NumberRecord
*/
public final class RKRecord extends StandardRecord implements CellValueRecordInterface {
public final static short sid = 0x027E;
public final static short RK_IEEE_NUMBER = 0;
public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
public final static short RK_INTEGER = 2;
public final static short RK_INTEGER_TIMES_100 = 3;
private int field_1_row;
private int field_2_col;
private int field_3_xf_index;
private int field_4_rk_number;
private RKRecord()
{
}
public RKRecord(RecordInputStream in)
{
field_1_row = in.readUShort();
field_2_col = in.readUShort();
field_3_xf_index = in.readUShort();
field_4_rk_number = in.readInt();
}
public int getRow()
{
return field_1_row;
}
public short getColumn()
{
return (short) field_2_col;
}
public short getXFIndex()
{
return (short) field_3_xf_index;
}
public int getRKField()
{
return field_4_rk_number;
}
/**
* Get the type of the number
*
* @return one of these values:
* <OL START="0">
* <LI>RK_IEEE_NUMBER</LI>
* <LI>RK_IEEE_NUMBER_TIMES_100</LI>
* <LI>RK_INTEGER</LI>
* <LI>RK_INTEGER_TIMES_100</LI>
* </OL>
*/
public short getRKType()
{
return ( short ) (field_4_rk_number & 3);
}
/**
* Extract the value of the number
* <P>
* The mechanism for determining the value is dependent on the two
* low order bits of the raw number. If bit 1 is set, the number
* is an integer and can be cast directly as a double, otherwise,
* it's apparently the exponent and mantissa of a double (and the
* remaining low-order bits of the double's mantissa are 0's).
* <P>
* If bit 0 is set, the result of the conversion to a double is
* divided by 100; otherwise, the value is left alone.
* <P>
* [insert picture of Screwy Squirrel in full Napoleonic regalia]
*
* @return the value as a proper double (hey, it <B>could</B>
* happen)
*/
public double getRKNumber()
{
return RKUtil.decodeNumber(field_4_rk_number);
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("[RK]\n");
sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
sb.append(" .col = ").append(HexDump.shortToHex(getColumn())).append("\n");
sb.append(" .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
sb.append(" .rknumber = ").append(HexDump.intToHex(getRKField())).append("\n");
sb.append(" .rktype = ").append(HexDump.byteToHex(getRKType())).append("\n");
sb.append(" .rknumber= ").append(getRKNumber()).append("\n");
sb.append("[/RK]\n");
return sb.toString();
}
public void serialize(LittleEndianOutput out) {
throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
}
protected int getDataSize() {
throw new RecordFormatException( "Sorry, you can't serialize RK in this release");
}
public short getSid()
{
return sid;
}
public void setColumn(short col)
{
}
public void setRow(int row)
{
}
/**
* NO OP!
*/
public void setXFIndex(short xf)
{
}
public Object clone() {
RKRecord rec = new RKRecord();
rec.field_1_row = field_1_row;
rec.field_2_col = field_2_col;
rec.field_3_xf_index = field_3_xf_index;
rec.field_4_rk_number = field_4_rk_number;
return rec;
}
}