2002-01-30 21:22:28 -05:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
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
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
==================================================================== */
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
package org.apache.poi.hssf.record;
|
|
|
|
|
2016-05-16 05:38:42 -04:00
|
|
|
import org.apache.poi.ss.usermodel.FormulaError;
|
2008-09-29 14:43:53 -04:00
|
|
|
import org.apache.poi.util.HexDump;
|
2008-11-18 13:49:19 -05:00
|
|
|
import org.apache.poi.util.LittleEndianOutput;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/**
|
2008-09-29 14:43:53 -04:00
|
|
|
* Creates new BoolErrRecord. (0x0205) <P>
|
2002-01-30 21:22:28 -05:00
|
|
|
* REFERENCE: PG ??? Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
|
|
|
|
* @author Michael P. Harhen
|
2002-09-04 20:26:28 -04:00
|
|
|
* @author Jason Height (jheight at chariot dot net dot au)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
2015-09-28 19:16:58 -04:00
|
|
|
public final class BoolErrRecord extends CellRecord implements Cloneable {
|
2009-01-13 19:22:00 -05:00
|
|
|
public final static short sid = 0x0205;
|
2009-07-06 15:59:32 -04:00
|
|
|
private int _value;
|
|
|
|
/**
|
|
|
|
* If <code>true</code>, this record represents an error cell value, otherwise this record represents a boolean cell value
|
|
|
|
*/
|
|
|
|
private boolean _isError;
|
2009-01-13 19:22:00 -05:00
|
|
|
|
|
|
|
/** Creates new BoolErrRecord */
|
|
|
|
public BoolErrRecord() {
|
2009-07-06 15:59:32 -04:00
|
|
|
// fields uninitialised
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param in the RecordInputstream to read the record from
|
|
|
|
*/
|
|
|
|
public BoolErrRecord(RecordInputStream in) {
|
2009-02-09 18:16:49 -05:00
|
|
|
super(in);
|
2009-07-06 15:59:32 -04:00
|
|
|
switch (in.remaining()) {
|
|
|
|
case 2:
|
|
|
|
_value = in.readByte();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_value = in.readUShort();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new RecordFormatException("Unexpected size ("
|
|
|
|
+ in.remaining() + ") for BOOLERR record.");
|
|
|
|
}
|
|
|
|
int flag = in.readUByte();
|
|
|
|
switch (flag) {
|
|
|
|
case 0:
|
|
|
|
_isError = false;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_isError = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new RecordFormatException("Unexpected isError flag ("
|
|
|
|
+ flag + ") for BOOLERR record.");
|
|
|
|
}
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the boolean value for the cell
|
|
|
|
*
|
|
|
|
* @param value representing the boolean value
|
|
|
|
*/
|
|
|
|
public void setValue(boolean value) {
|
2009-07-06 15:59:32 -04:00
|
|
|
_value = value ? 1 : 0;
|
|
|
|
_isError = false;
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-13 06:53:03 -04:00
|
|
|
* set the error value for the cell. See {@link FormulaError} for valid codes.
|
2009-01-13 19:22:00 -05:00
|
|
|
*
|
|
|
|
* @param value error representing the error value
|
|
|
|
* this value can only be 0,7,15,23,29,36 or 42
|
|
|
|
* see bugzilla bug 16560 for an explanation
|
|
|
|
*/
|
|
|
|
public void setValue(byte value) {
|
2016-06-13 06:53:03 -04:00
|
|
|
setValue(FormulaError.forInt(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the error value for the cell
|
|
|
|
*
|
|
|
|
* @param value error representing the error value
|
|
|
|
* this value can only be 0,7,15,23,29,36 or 42
|
|
|
|
* see bugzilla bug 16560 for an explanation
|
|
|
|
*/
|
|
|
|
public void setValue(FormulaError value) {
|
|
|
|
switch(value) {
|
2016-05-16 05:38:42 -04:00
|
|
|
case NULL:
|
|
|
|
case DIV0:
|
|
|
|
case VALUE:
|
|
|
|
case REF:
|
|
|
|
case NAME:
|
|
|
|
case NUM:
|
|
|
|
case NA:
|
2016-06-13 06:53:03 -04:00
|
|
|
_value = value.getCode();
|
2009-07-06 15:59:32 -04:00
|
|
|
_isError = true;
|
2009-01-13 19:22:00 -05:00
|
|
|
return;
|
2016-05-16 05:38:42 -04:00
|
|
|
default:
|
2016-06-13 06:53:03 -04:00
|
|
|
throw new IllegalArgumentException("Error Value can only be 0,7,15,23,29,36 or 42. It cannot be "+value.getCode()+" ("+value+")");
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the value for the cell
|
|
|
|
*
|
|
|
|
* @return boolean representing the boolean value
|
|
|
|
*/
|
|
|
|
public boolean getBooleanValue() {
|
2009-07-06 15:59:32 -04:00
|
|
|
return _value != 0;
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the error value for the cell
|
|
|
|
*
|
|
|
|
* @return byte representing the error value
|
|
|
|
*/
|
|
|
|
public byte getErrorValue() {
|
2009-07-06 15:59:32 -04:00
|
|
|
return (byte)_value;
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the call holds a boolean value
|
|
|
|
*
|
|
|
|
* @return boolean true if the cell holds a boolean value
|
|
|
|
*/
|
|
|
|
public boolean isBoolean() {
|
2009-07-06 15:59:32 -04:00
|
|
|
return !_isError;
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the call holds an error value
|
|
|
|
*
|
|
|
|
* @return boolean true if the cell holds an error value
|
|
|
|
*/
|
|
|
|
public boolean isError() {
|
2009-07-06 15:59:32 -04:00
|
|
|
return _isError;
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
2009-02-09 18:16:49 -05:00
|
|
|
@Override
|
|
|
|
protected String getRecordName() {
|
|
|
|
return "BOOLERR";
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected void appendValueText(StringBuilder sb) {
|
2009-01-13 19:22:00 -05:00
|
|
|
if (isBoolean()) {
|
2009-02-09 18:16:49 -05:00
|
|
|
sb.append(" .boolVal = ");
|
|
|
|
sb.append(getBooleanValue());
|
2009-01-13 19:22:00 -05:00
|
|
|
} else {
|
2009-02-09 18:16:49 -05:00
|
|
|
sb.append(" .errCode = ");
|
2016-05-16 05:38:42 -04:00
|
|
|
sb.append(FormulaError.forInt(getErrorValue()).getString());
|
2009-02-09 18:16:49 -05:00
|
|
|
sb.append(" (").append(HexDump.byteToHex(getErrorValue())).append(")");
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
}
|
2009-02-09 18:16:49 -05:00
|
|
|
@Override
|
|
|
|
protected void serializeValue(LittleEndianOutput out) {
|
2009-07-06 15:59:32 -04:00
|
|
|
out.writeByte(_value);
|
|
|
|
out.writeByte(_isError ? 1 : 0);
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
2009-02-09 18:16:49 -05:00
|
|
|
@Override
|
|
|
|
protected int getValueDataSize() {
|
|
|
|
return 2;
|
2009-01-13 19:22:00 -05:00
|
|
|
}
|
|
|
|
|
2009-02-09 18:16:49 -05:00
|
|
|
public short getSid() {
|
2009-01-13 19:22:00 -05:00
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
2015-09-28 19:16:58 -04:00
|
|
|
@Override
|
|
|
|
public BoolErrRecord clone() {
|
2009-01-13 19:22:00 -05:00
|
|
|
BoolErrRecord rec = new BoolErrRecord();
|
2009-02-09 18:16:49 -05:00
|
|
|
copyBaseFields(rec);
|
2009-07-06 15:59:32 -04:00
|
|
|
rec._value = _value;
|
|
|
|
rec._isError = _isError;
|
2009-01-13 19:22:00 -05:00
|
|
|
return rec;
|
|
|
|
}
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|