01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.record.formula;
19:
20: import org.apache.poi.hssf.model.Workbook;
21: import org.apache.poi.hssf.record.RecordInputStream;
22: import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
23:
24: /**
25: * @author Daniel Noll (daniel at nuix dot com dot au)
26: */
27: public class ErrPtg extends Ptg {
28: public static final short sid = 0x1c;
29: private static final int SIZE = 7;
30: private byte field_1_error_code;
31:
32: /** Creates new ErrPtg */
33:
34: public ErrPtg() {
35: }
36:
37: public ErrPtg(RecordInputStream in) {
38: field_1_error_code = in.readByte();
39: }
40:
41: public void writeBytes(byte[] array, int offset) {
42: array[offset] = (byte) (sid + ptgClass);
43: array[offset + 1] = field_1_error_code;
44: }
45:
46: public String toFormulaString(Workbook book) {
47: switch (field_1_error_code) {
48: case HSSFErrorConstants.ERROR_NULL:
49: return "#NULL!";
50: case HSSFErrorConstants.ERROR_DIV_0:
51: return "#DIV/0!";
52: case HSSFErrorConstants.ERROR_VALUE:
53: return "#VALUE!";
54: case HSSFErrorConstants.ERROR_REF:
55: return "#REF!";
56: case HSSFErrorConstants.ERROR_NAME:
57: return "#NAME?";
58: case HSSFErrorConstants.ERROR_NUM:
59: return "#NUM!";
60: case HSSFErrorConstants.ERROR_NA:
61: return "#N/A";
62: }
63:
64: // Shouldn't happen anyway. Excel docs say that this is returned for all other codes.
65: return "#N/A";
66: }
67:
68: public int getSize() {
69: return SIZE;
70: }
71:
72: public byte getDefaultOperandClass() {
73: return Ptg.CLASS_VALUE;
74: }
75:
76: public Object clone() {
77: ErrPtg ptg = new ErrPtg();
78: ptg.field_1_error_code = field_1_error_code;
79: return ptg;
80: }
81: }
|