org.ttzero.excel.entity.style.XFParser 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.Block;
import org.ttzero.excel.entity.e3.Option;
import org.ttzero.excel.entity.e3.ParserIdentifier;
/**
* 5.115 XF – Extended Format
*
* This record contains formatting information for
* cells, rows, columns or styles.
*
* @author guanquan.wang at 2019-03-02 09:13
*/
public class XFParser {
public static XF get(Block block) {
block.ready();
XF xf = new XF();
// TODO All in e7.style
// 0 2 Index to FONT record (➜5.45)
xf.font = block.nextUnsignedShort();
// 2 2 Index to FORMAT record (➜5.49)
xf.format = block.nextUnsignedShort();
// 4 2 XF type, cell protection, and parent style XF:
// 2-0 | 0007H | XF_TYPE_PROT – XF type, cell protection (see above)
// 15-4 | FFF0H | Index to parent style XF (always FFFH in style XFs)
xf.type = Option.of(block.nextUnsignedShort());
// 6 1 Alignment and text break:
// 2-0 | 07H | XF_HOR_ALIGN – Horizontal alignment (see above)
// 3 | 08H | 1 = Text is wrapped at right border
// 6-4 | 70H | XF_VERT_ALIGN – Vertical alignment (see above)
// 7 | 80H | 1 = Justify last line in justified or distibuted text
xf.alignment = Option.of(block.nextByte());
// 7 1 XF_ROTATION: Text rotation angle (see above)
xf.rotation = block.nextByte();
// 8 1 Indentation, shrink to cell size, and text direction:
// 3-0 | 0FH | Indent level
// 4 | 10H | 1 = Shrink content to fit into cell
// 7-6 | C0H | Text direction:
// 0 = According to context35; 1 = Left-to-right; 2 = Right-to-left
xf.indentation = Option.of(block.nextByte());
// 9 1 Flags for used attribute groups:
// 7-2 | FCH | XF_USED_ATTRIB – Used attributes (see above)
xf.attributeGroups = Option.of(block.nextByte());
// 10 4 Cell border lines and background area:
// 3-0 | 0000000FH | Left line style
// 7-4 | 000000F0H | Right line style
// 11-8 | 00000F00H | Top line style
// 15-12| 0000F000H | Bottom line style
// 22-16| 007F0000H | Colour index for left line colour
// 29-23| 3F800000H | Colour index for right line colour
// 30 | 40000000H | 1 = Diagonal line from top left to right bottom
// 31 | 80000000H | 1 = Diagonal line from bottom left to right top
xf.border = Option.of(block.nextInt());
// 14 4 Colour
// 6-0 | 0000007FH | Colour index for top line colour
// 13-7 | 00003F80H | Colour index for bottom line colour
// 20-14| 001FC000H | Colour index for diagonal line colour
// 24-21| 01E00000H | Diagonal line style
// 31-26| FC000000H | Fill pattern
xf.colour = Option.of(block.nextInt());
// 18 2 Fill
// 6-0 | 007FH | Colour index for pattern colour
// 13-7 | 3F80H | Colour index for pattern background
xf.fill = Option.of(block.nextUnsignedShort());
block.commit();
return xf;
}
public static short getId() {
return ParserIdentifier.XF;
}
/**
* Record XF, BIFF8
*/
public static class XF {
public int id;
public int font;
public int format;
public Option type;
public Option alignment;
public byte rotation;
public Option indentation;
public Option attributeGroups;
public Option border;
public Option colour;
public Option fill;
}
}