📄 namerecord.java
字号:
/* ==================================================================== Copyright 2002-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;import java.util.List;import java.util.Stack;import org.apache.poi.hssf.model.Workbook;import org.apache.poi.hssf.record.formula.Area3DPtg;import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;import org.apache.poi.hssf.record.formula.Ptg;import org.apache.poi.hssf.record.formula.Ref3DPtg;import org.apache.poi.hssf.util.RangeAddress;import org.apache.poi.util.HexDump;import org.apache.poi.util.LittleEndian;import org.apache.poi.util.StringUtil;/** * Title: Name Record (aka Named Range) <P> * Description: Defines a named range within a workbook. <P> * REFERENCE: <P> * @author Libin Roman (Vista Portal LDT. Developer) * @author Sergei Kozello (sergeikozello at mail.ru) * @author Glen Stampoultzis (glens at apache.org) * @version 1.0-pre */public class NameRecord extends Record { /** */ public final static short sid = 0x18; //Docs says that it is 0x218 /**Included for completeness sake, not implemented */ public final static byte BUILTIN_CONSOLIDATE_AREA = (byte)1; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_AUTO_OPEN = (byte)2; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_AUTO_CLOSE = (byte)3; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_DATABASE = (byte)4; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_CRITERIA = (byte)5; public final static byte BUILTIN_PRINT_AREA = (byte)6; public final static byte BUILTIN_PRINT_TITLE = (byte)7; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_RECORDER = (byte)8; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_DATA_FORM = (byte)9; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_AUTO_ACTIVATE = (byte)10; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_AUTO_DEACTIVATE = (byte)11; /**Included for completeness sake, not implemented */ public final static byte BUILTIN_SHEET_TITLE = (byte)12; public static final short OPT_HIDDEN_NAME = (short) 0x0001; public static final short OPT_FUNCTION_NAME = (short) 0x0002; public static final short OPT_COMMAND_NAME = (short) 0x0004; public static final short OPT_MACRO = (short) 0x0008; public static final short OPT_COMPLEX = (short) 0x0010; public static final short OPT_BUILTIN = (short) 0x0020; public static final short OPT_BINDATA = (short) 0x1000; private short field_1_option_flag; private byte field_2_keyboard_shortcut; private byte field_3_length_name_text; private short field_4_length_name_definition; private short field_5_index_to_sheet; // unused: see field_6 private short field_6_equals_to_index_to_sheet; private byte field_7_length_custom_menu; private byte field_8_length_description_text; private byte field_9_length_help_topic_text; private byte field_10_length_status_bar_text; private byte field_11_compressed_unicode_flag; // not documented private byte field_12_builtIn_name; private String field_12_name_text; private Stack field_13_name_definition; private byte[] field_13_raw_name_definition; // raw data private String field_14_custom_menu_text; private String field_15_description_text; private String field_16_help_topic_text; private String field_17_status_bar_text; /** Creates new NameRecord */ public NameRecord() { field_13_name_definition = new Stack(); field_12_name_text = new String(); field_14_custom_menu_text = new String(); field_15_description_text = new String(); field_16_help_topic_text = new String(); field_17_status_bar_text = new String(); } /** * Constructs a Name record and sets its fields appropriately. * * @param id id must be 0x18 or an exception will be throw upon validation * @param size the size of the data area of the record * @param data data of the record (should not contain sid/len) */ public NameRecord(short id, short size, byte [] data) { super(id, size, data); } /** * Constructs a Name record and sets its fields appropriately. * * @param id id must be 0x18 or an exception will be throw upon validation * @param size the size of the data area of the record * @param data data of the record (should not contain sid/len) * @param offset of the record's data */ public NameRecord(short id, short size, byte [] data, int offset) { super(id, size, data, offset); } /** * Constructor to create a built-in named region * @param builtin Built-in byte representation for the name record, use the public constants * @param index */ public NameRecord(byte builtin, short index) { this(); this.field_12_builtIn_name = builtin; this.setOptionFlag((short)(this.getOptionFlag() | OPT_BUILTIN)); this.setNameTextLength((byte)1); this.setEqualsToIndexToSheet(index); //the extern sheets are set through references //clearing these because they are not used with builtin records this.setCustomMenuLength((byte)0); this.setDescriptionTextLength((byte)0); this.setHelpTopicLength((byte)0); this.setStatusBarLength((byte)0); } /** sets the option flag for the named range * @param flag option flag */ public void setOptionFlag(short flag){ field_1_option_flag = flag; } /** sets the keyboard shortcut * @param shortcut keyboard shortcut */ public void setKeyboardShortcut(byte shortcut){ field_2_keyboard_shortcut = shortcut; } /** sets the name of the named range length * @param length name length */ public void setNameTextLength(byte length){ field_3_length_name_text = length; } /** sets the definition (reference - formula) length * @param length defenition length */ public void setDefinitionTextLength(short length){ field_4_length_name_definition = length; } /** sets the index number to the extern sheet (thats is what writen in documentation * but as i saw , it works differently) * @param index extern sheet index */ public void setUnused(short index){ field_5_index_to_sheet = index; // field_6_equals_to_index_to_sheet is equal to field_5_index_to_sheet// field_6_equals_to_index_to_sheet = index; } public short getEqualsToIndexToSheet() { return field_6_equals_to_index_to_sheet; } /** * Convenience method to retrieve the index the name refers to. * @see #getEqualsToIndexToSheet() * @return short */ public short getIndexToSheet() { return getEqualsToIndexToSheet(); } /** * @return function group * @see FnGroupCountRecord */ public byte getFnGroup() { int masked = field_1_option_flag & 0x0fc0; return (byte) (masked >> 4); } public void setEqualsToIndexToSheet(short value) { field_6_equals_to_index_to_sheet = value; } /** sets the custom menu length * @param length custom menu length */ public void setCustomMenuLength(byte length){ field_7_length_custom_menu = length; } /** sets the length of named range description * @param length description length */ public void setDescriptionTextLength(byte length){ field_8_length_description_text = length; } /** sets the help topic length * @param length help topic length */ public void setHelpTopicLength(byte length){ field_9_length_help_topic_text = length; } /** sets the length of the status bar text * @param length status bar text length */ public void setStatusBarLength(byte length){ field_10_length_status_bar_text = length; } /** sets the compressed unicode flag * @param flag unicode flag */ public void setCompressedUnicodeFlag(byte flag) { field_11_compressed_unicode_flag = flag; } /** sets the name of the named range * @param name named range name */ public void setNameText(String name){ field_12_name_text = name; } // public void setNameDefintion(String definition){ // test = definition; // } /** sets the custom menu text * @param text custom menu text */ public void setCustomMenuText(String text){ field_14_custom_menu_text = text; } /** sets the description text * @param text the description text */ public void setDescriptionText(String text){ field_15_description_text = text; } /** sets the help topic text * @param text help topix text */ public void setHelpTopicText(String text){ field_16_help_topic_text = text; } /** sets the status bar text * @param text status bar text */ public void setStatusBarText(String text){ field_17_status_bar_text = text; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -