namerecord.java

来自「EXCEL read and write」· Java 代码 · 共 677 行 · 第 1/2 页

JAVA
677
字号
/* ====================================================================   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 java.util.ArrayList;import java.util.List;import org.apache.poi.hssf.model.HSSFFormulaParser;import org.apache.poi.hssf.record.formula.Area3DPtg;import org.apache.poi.hssf.record.formula.Ptg;import org.apache.poi.hssf.record.formula.Ref3DPtg;import org.apache.poi.hssf.record.formula.UnionPtg;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.hssf.util.AreaReference;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:        DEFINEDNAME Record (0x0018) <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 final class NameRecord extends Record {    public final static short sid = 0x0018;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_CONSOLIDATE_AREA      = 1;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_AUTO_OPEN             = 2;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_AUTO_CLOSE            = 3;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_DATABASE              = 4;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_CRITERIA              = 5;	public final static byte  BUILTIN_PRINT_AREA            = 6;	public final static byte  BUILTIN_PRINT_TITLE           = 7;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_RECORDER              = 8;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_DATA_FORM             = 9;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_AUTO_ACTIVATE         = 10;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_AUTO_DEACTIVATE       = 11;	/**Included for completeness sake, not implemented */	public final static byte  BUILTIN_SHEET_TITLE           = 12;	public final static byte  BUILTIN_FILTER_DB             = 13;	private static final class Option {		public static final int OPT_HIDDEN_NAME =   0x0001;		public static final int OPT_FUNCTION_NAME = 0x0002;		public static final int OPT_COMMAND_NAME =  0x0004;		public static final int OPT_MACRO =         0x0008;		public static final int OPT_COMPLEX =       0x0010;		public static final int OPT_BUILTIN =       0x0020;		public static final int OPT_BINDATA =       0x1000;	}	private short             field_1_option_flag;	private byte              field_2_keyboard_shortcut;	/** One-based extern index of sheet (resolved via LinkTable). Zero if this is a global name  */	private short             field_5_externSheetIndex_plus1;	/** the one based sheet number.  */	private int               field_6_sheetNumber;	private boolean           field_11_nameIsMultibyte;	private byte              field_12_built_in_code;	private String            field_12_name_text;	private Ptg[]             field_13_name_definition;	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 = Ptg.EMPTY_PTG_ARRAY;		field_12_name_text = "";		field_14_custom_menu_text = "";		field_15_description_text = "";		field_16_help_topic_text = "";		field_17_status_bar_text = "";	}	/**	 * Constructor to create a built-in named region	 * @param builtin Built-in byte representation for the name record, use the public constants	 */	public NameRecord(byte builtin, int sheetNumber)	{		this();		field_12_built_in_code = builtin;		setOptionFlag((short)(field_1_option_flag | Option.OPT_BUILTIN));		field_6_sheetNumber = sheetNumber; //the extern sheets are set through references	}	/** 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;	}	/**	 * For named ranges, and built-in names	 * @return the 1-based sheet number. 	 */	public int getSheetNumber()	{		return field_6_sheetNumber;	}	/**	 * @return function group	 * @see FnGroupCountRecord	 */	public byte getFnGroup() {		int masked = field_1_option_flag & 0x0fc0;		return (byte) (masked >> 4);	}	public void setSheetNumber(int value)	{		field_6_sheetNumber = value;	}	/** sets the name of the named range	 * @param name named range name	 */	public void setNameText(String name){		field_12_name_text = name;		field_11_nameIsMultibyte = StringUtil.hasMultibyte(name);	}	/** 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;	}	/** gets the option flag	 * @return option flag	 */	public short getOptionFlag(){		return field_1_option_flag;	}	/** returns the keyboard shortcut	 * @return keyboard shortcut	 */	public byte getKeyboardShortcut(){		return field_2_keyboard_shortcut ;	}	/**	 * gets the name length, in characters	 * @return name length	 */	private int getNameTextLength(){		if (isBuiltInName()) {			return 1;		}		return field_12_name_text.length();	}	/**	 * @return true if name is hidden	 */	public boolean isHiddenName() {		return (field_1_option_flag & Option.OPT_HIDDEN_NAME) != 0;	}	public void setHidden(boolean b) {		if (b) {			field_1_option_flag |= Option.OPT_HIDDEN_NAME;		} else {			field_1_option_flag &= (~Option.OPT_HIDDEN_NAME);		}	}	/**	 * @return <code>true</code> if name is a function	 */	public boolean isFunctionName() {		return (field_1_option_flag & Option.OPT_FUNCTION_NAME) != 0;	}	/**	 * @return <code>true</code> if name has a formula (named range or defined value)	 */	public boolean hasFormula() {		return field_1_option_flag == 0 && field_13_name_definition.length > 0;	}	/**	 * @return true if name is a command	 */	public boolean isCommandName() {		return (field_1_option_flag & Option.OPT_COMMAND_NAME) != 0;	}	/**	 * @return true if function macro or command macro	 */	public boolean isMacro() {		return (field_1_option_flag & Option.OPT_MACRO) != 0;	}	/**	 * @return true if array formula or user defined	 */	public boolean isComplexFunction() {		return (field_1_option_flag & Option.OPT_COMPLEX) != 0;	}	/**Convenience Function to determine if the name is a built-in name	 */	public boolean isBuiltInName()	{		return ((field_1_option_flag & Option.OPT_BUILTIN) != 0);	}	/** gets the name	 * @return name	 */	public String getNameText(){		return isBuiltInName() ? translateBuiltInName(getBuiltInName()) : field_12_name_text;	}	/** Gets the Built In Name	 * @return the built in Name	 */	public byte getBuiltInName()	{		return field_12_built_in_code;	}	/** gets the definition, reference (Formula)	 * @return the name formula. never <code>null</code>	 */	public Ptg[] getNameDefinition() {		return (Ptg[]) field_13_name_definition.clone();	}	public void setNameDefinition(Ptg[] ptgs) {		field_13_name_definition = (Ptg[]) ptgs.clone();	}	/** get the custom menu text	 * @return custom menu text	 */	public String getCustomMenuText(){		return field_14_custom_menu_text;	}	/** gets the description text	 * @return description text	 */	public String getDescriptionText(){		return field_15_description_text;	}	/** get the help topic text	 * @return gelp topic text	 */	public String getHelpTopicText(){		return field_16_help_topic_text;	}	/** gets the status bar text	 * @return status bar text	 */	public String getStatusBarText(){		return field_17_status_bar_text;	}	/**	 * called by the class that is responsible for writing this sucker.	 * Subclasses should implement this so that their data is passed back in a	 * @param offset to begin writing at	 * @param data byte array containing instance data

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?