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

org.ttzero.excel.entity.style.StyleParser Maven / Gradle / Ivy

/*
 * Copyright (c) 2019-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.style;

import org.ttzero.excel.entity.e3.StringParser;
import org.ttzero.excel.entity.e3.Block;
import org.ttzero.excel.entity.e3.Option;
import org.ttzero.excel.entity.e3.ParserIdentifier;

/**
 * 5.103 STYLE
 * 

* This record stores the name of a user-defined cell * style or specific options for a built-in cell style. * All STYLE records occur together behind the XF record list (➜5.115). * Each STYLE record refers to a style XF record, * which contains the formatting attributes for the cell style. * * @author guanquan.wang on 2019-02-05 */ public class StyleParser { public static Style get(Block block) { block.ready(); Option option = Option.of(block.nextShort()); Style style = new Style(); // Index to style XF record (➜5.115) style.xf = (short) option.range(0, 11); // Always 0 for user-defined styles // Always 1 for built-in styles style.userDefined = option.isOff(15); // 5.103.1 User-Defined Cell Styles if (style.userDefined) { style.name = StringParser.get16Bit(block); // 5.103.2 Built-In Cell Styles } else { // Identifier of the built-in cell style: // 00H = Normal // 01H = RowLevel_lv (see next field) 02H = ColLevel_lv (see next field) 03H = Comma // 04H = Currency // 05H = Percent // 06H = Comma [0] (BIFF4-BIFF8) 07H = Currency [0] (BIFF4-BIFF8) 08H = Hyperlink (BIFF8) // 09H = Followed Hyperlink (BIFF8) style.builtInStyle = block.nextByte(); // Level for RowLevel or ColLevel style (zero-based, lv), FFH otherwise style.lv = block.nextByte(); } block.commit(); return style; } public static short getId() { return ParserIdentifier.STYLE; } public static class Style { short xf; boolean userDefined; String name; byte builtInStyle; byte lv; @Override public String toString() { String s; if (userDefined) { s = "User-Defined Cell Style xf: " + xf + " name: " + name; } else { s = "Built-In Cell Style xf: " + xf + " style: " + builtInStyle + " lv: " + lv; } return s; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy