All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ttzero.excel.entity.e3.DefinedNameParser Maven / Gradle / Ivy

/*
 * Copyright (c) 2017-2020, [email protected] All Rights Reserved.
 *
 * 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.ttzero.excel.entity.e3;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;

/**
 * 5.33 DEFINEDNAME
 * 

* This record is part of a Link Table (➜4.10). It contains * the name and the token array of an internal defined name. Token * arrays of defined names contain tokens with aberrant token * classes (➜3.2). * * @author guanquan.wang at 2020-04-21 20:52 */ public class DefinedNameParser { private static final Logger LOGGER = LoggerFactory.getLogger(DefinedNameParser.class); public static void get(Block block) { block.ready(); /* 0 2 Option flags Bit | Mask | Flag | name Contents ----|-------|----------|---------------------------- 0 | 0001H | hidden | 0 = Visible 1 = Hidden 1 | 0002H | func | 0 = Command macro 1 = Function macro 2 | 0004H | vbasic | 0 = Sheet macro 1 = VisualBasic macro 3 | 0008H | macro | 0 = Standard name 1 = Macro name (see below) 4 | 0010H | complex | 0 = Simple formula 1 = Complex formula (array formula or user defined) 5 | 0020H | builtin | 0 = User-defined name 1 = Built-in name (see below) 11-6| 0FC0H | funcgroup| Function group (BIFF4-BIFF8), only if macro = 1, must be >0 then 1 = Financial 8 = Logical 2 = Date & Time 9 = Information 3 = Math & Trig 10 = Commands 4 = Statistical 11 = Customizing 5 = Lookup & Reference 12 = Macro Control 6 = Database 13 = DDE/External 7 = Text 14 = User Defined 12 | 1000H | binary | 0 = Formula definition 1 = Binary data (BIFF5-BIFF8) */ Option option = Option.of(block.nextShort()); LOGGER.debug("Option: {}", option); // 2 1 Keyboard shortcut (only for command macro names) block.nextByte(); // 3 1 Length of the name (character count, ln) int ln = block.nextByte() & 0x7FFFFFFF; // 4 2 Size of the formula data (sz) int sz = block.nextUnsignedShort(); // 6 2 Not used block.skip(2); // 8 2 0 = Global name, otherwise index to sheet (one-based) int n = block.nextUnsignedShort(); // 10 1 Length of menu text (character count, lm) int lm = block.nextByte() & 0x7FFFFFFF; // 11 1 Length of description text (character count, ld) int ld = block.nextByte() & 0x7FFFFFFF; // 12 1 Length of help topic text (character count, lh) int lh = block.nextByte() & 0x7FFFFFFF; // 13 1 Length of status bar text (character count, ls) int ls = block.nextByte() & 0x7FFFFFFF; // 14 var. Name (Unicode string without length field, ➜2.5.3) String name = block.nextString(ln >> 1, StandardCharsets.UTF_16LE); LOGGER.debug("Name: {}", name); // var. sz Formula data (RPN token array without size field, ➜3) byte[] bytes = block.range(sz); // [var.] var. (optional, only if lm > 0) Menu text (Unicode string without length field, ➜2.5.3) if (lm > 0) { String menu = block.nextString(lm >> 1, StandardCharsets.UTF_16LE); LOGGER.debug("Menu text: {}", menu); } // [var.] var. (optional, only if ld > 0) Description text (Unicode string without length field, ➜2.5.3) if (ld > 0) { String desc = block.nextString(ld >> 1, StandardCharsets.UTF_16LE); LOGGER.debug("Description text: {}", desc); } // [var.] var. (optional, only if lh > 0) Help topic text (Unicode string without length field, ➜2.5.3) if (lh > 0) { String topic = block.nextString(lh >> 1, StandardCharsets.UTF_16LE); LOGGER.debug("Help topic text: {}", topic); } // [var.] var. (optional, only if ls > 0) Status bar text (Unicode string without length field, ➜2.5.3) if (ls > 0) { String statusBar = block.nextString(ls >> 1, StandardCharsets.UTF_16LE); LOGGER.debug("Status bar text: {}", statusBar); } block.commit(); } public static short getId() { return ParserIdentifier.DEFINEDNAME; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy