📄 abstractfunctionptg.java
字号:
/* ==================================================================== Copyright 2003-2004 Apache Software Foundation Licensed 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.formula;import org.apache.poi.util.BinaryTree;import org.apache.poi.hssf.model.Workbook;/** * This class provides the base functionality for Excel sheet functions * There are two kinds of function Ptgs - tFunc and tFuncVar * Therefore, this class will have ONLY two subclasses * @author Avik Sengupta * @author Andrew C. Oliver (acoliver at apache dot org) */public abstract class AbstractFunctionPtg extends OperationPtg { //constant used allow a ptgAttr to be mapped properly for its functionPtg public static final String ATTR_NAME = "specialflag"; public static final short INDEX_EXTERNAL = 255; private static BinaryTree map = produceHash(); protected static Object[][] functionData = produceFunctionData(); protected byte returnClass; protected byte[] paramClass; protected byte field_1_num_args; protected short field_2_fnc_index; public String toString() { StringBuffer buffer = new StringBuffer(); buffer .append("<FunctionPtg>").append("\n") .append(" field_1_num_args=").append(field_1_num_args).append("\n") .append(" name =").append(lookupName(field_2_fnc_index)).append("\n") .append(" field_2_fnc_index=").append(field_2_fnc_index).append("\n") .append("</FunctionPtg>"); return buffer.toString(); } public int getType() { return -1; } public short getFunctionIndex() { return field_2_fnc_index; } public String getName() { return lookupName(field_2_fnc_index); } public String toFormulaString(Workbook book) { return getName(); } public String toFormulaString(String[] operands) { StringBuffer buf = new StringBuffer(); if (field_2_fnc_index != 1) { buf.append(getName()); buf.append('('); } if (operands.length >0) { for (int i=0;i<operands.length;i++) { buf.append(operands[i]); buf.append(','); } buf.deleteCharAt(buf.length()-1); } if (field_2_fnc_index != 1) { buf.append(")"); } return buf.toString(); } public abstract void writeBytes(byte[] array, int offset); public abstract int getSize(); protected String lookupName(short index) { return ((String)map.get(new Integer(index))); } protected short lookupIndex(String name) { Integer index = (Integer) map.getKeyForValue(name); if (index != null) return index.shortValue(); return INDEX_EXTERNAL; } /** * Produces the function table hashmap */ private static BinaryTree produceHash() { BinaryTree dmap = new BinaryTree(); dmap.put(new Integer(0),"COUNT"); dmap.put(new Integer(1),"specialflag"); dmap.put(new Integer(2),"ISNA"); dmap.put(new Integer(3),"ISERROR"); dmap.put(new Integer(4),"SUM"); dmap.put(new Integer(5),"AVERAGE"); dmap.put(new Integer(6),"MIN"); dmap.put(new Integer(7),"MAX"); dmap.put(new Integer(8),"ROW"); dmap.put(new Integer(9),"COLUMN"); dmap.put(new Integer(10),"NA"); dmap.put(new Integer(11),"NPV"); dmap.put(new Integer(12),"STDEV"); dmap.put(new Integer(13),"DOLLAR"); dmap.put(new Integer(14),"FIXED"); dmap.put(new Integer(15),"SIN"); dmap.put(new Integer(16),"COS"); dmap.put(new Integer(17),"TAN"); dmap.put(new Integer(18),"ATAN"); dmap.put(new Integer(19),"PI"); dmap.put(new Integer(20),"SQRT"); dmap.put(new Integer(21),"EXP"); dmap.put(new Integer(22),"LN"); dmap.put(new Integer(23),"LOG10"); dmap.put(new Integer(24),"ABS"); dmap.put(new Integer(25),"INT"); dmap.put(new Integer(26),"SIGN"); dmap.put(new Integer(27),"ROUND"); dmap.put(new Integer(28),"LOOKUP"); dmap.put(new Integer(29),"INDEX"); dmap.put(new Integer(30),"REPT"); dmap.put(new Integer(31),"MID"); dmap.put(new Integer(32),"LEN"); dmap.put(new Integer(33),"VALUE"); dmap.put(new Integer(34),"TRUE"); dmap.put(new Integer(35),"FALSE"); dmap.put(new Integer(36),"AND"); dmap.put(new Integer(37),"OR"); dmap.put(new Integer(38),"NOT"); dmap.put(new Integer(39),"MOD"); dmap.put(new Integer(40),"DCOUNT"); dmap.put(new Integer(41),"DSUM"); dmap.put(new Integer(42),"DAVERAGE"); dmap.put(new Integer(43),"DMIN"); dmap.put(new Integer(44),"DMAX"); dmap.put(new Integer(45),"DSTDEV"); dmap.put(new Integer(46),"VAR"); dmap.put(new Integer(47),"DVAR"); dmap.put(new Integer(48),"TEXT"); dmap.put(new Integer(49),"LINEST"); dmap.put(new Integer(50),"TREND"); dmap.put(new Integer(51),"LOGEST"); dmap.put(new Integer(52),"GROWTH"); dmap.put(new Integer(53),"GOTO"); dmap.put(new Integer(54),"HALT"); dmap.put(new Integer(56),"PV"); dmap.put(new Integer(57),"FV"); dmap.put(new Integer(58),"NPER"); dmap.put(new Integer(59),"PMT"); dmap.put(new Integer(60),"RATE"); dmap.put(new Integer(61),"MIRR"); dmap.put(new Integer(62),"IRR"); dmap.put(new Integer(63),"RAND"); dmap.put(new Integer(64),"MATCH"); dmap.put(new Integer(65),"DATE"); dmap.put(new Integer(66),"TIME"); dmap.put(new Integer(67),"DAY"); dmap.put(new Integer(68),"MONTH"); dmap.put(new Integer(69),"YEAR"); dmap.put(new Integer(70),"WEEKDAY"); dmap.put(new Integer(71),"HOUR"); dmap.put(new Integer(72),"MINUTE"); dmap.put(new Integer(73),"SECOND"); dmap.put(new Integer(74),"NOW"); dmap.put(new Integer(75),"AREAS"); dmap.put(new Integer(76),"ROWS"); dmap.put(new Integer(77),"COLUMNS"); dmap.put(new Integer(78),"OFFSET"); dmap.put(new Integer(79),"ABSREF"); dmap.put(new Integer(80),"RELREF"); dmap.put(new Integer(81),"ARGUMENT"); dmap.put(new Integer(82),"SEARCH"); dmap.put(new Integer(83),"TRANSPOSE"); dmap.put(new Integer(84),"ERROR"); dmap.put(new Integer(85),"STEP"); dmap.put(new Integer(86),"TYPE"); dmap.put(new Integer(87),"ECHO"); dmap.put(new Integer(88),"SETNAME"); dmap.put(new Integer(89),"CALLER"); dmap.put(new Integer(90),"DEREF"); dmap.put(new Integer(91),"WINDOWS"); dmap.put(new Integer(92),"SERIES"); dmap.put(new Integer(93),"DOCUMENTS"); dmap.put(new Integer(94),"ACTIVECELL"); dmap.put(new Integer(95),"SELECTION"); dmap.put(new Integer(96),"RESULT");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -