📄 extendedformatrecord.java
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache POI" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache POI", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package org.apache.poi.hssf.record;import org.apache.poi.util.BitField;import org.apache.poi.util.LittleEndian;/** * Title: Extended Format Record * Description: Probably one of the more complex records. There are two breeds: * Style and Cell. *<P> * It should be noted that fields in the extended format record are * somewhat arbitrary. Almost all of the fields are bit-level, but * we name them as best as possible by functional group. In some * places this is better than others. *<P> * * REFERENCE: PG 426 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> * @author Andrew C. Oliver (acoliver at apache dot org) * @version 2.0-pre */public class ExtendedFormatRecord extends Record{ public final static short sid = 0xE0; // null constant public final static short NULL = (short)0xfff0; // xf type public final static short XF_STYLE = 1; public final static short XF_CELL = 0; // borders public final static short NONE = 0x0; public final static short THIN = 0x1; public final static short MEDIUM = 0x2; public final static short DASHED = 0x3; public final static short DOTTED = 0x4; public final static short THICK = 0x5; public final static short DOUBLE = 0x6; public final static short HAIR = 0x7; public final static short MEDIUM_DASHED = 0x8; public final static short DASH_DOT = 0x9; public final static short MEDIUM_DASH_DOT = 0xA; public final static short DASH_DOT_DOT = 0xB; public final static short MEDIUM_DASH_DOT_DOT = 0xC; public final static short SLANTED_DASH_DOT = 0xD; // alignment public final static short GENERAL = 0x0; public final static short LEFT = 0x1; public final static short CENTER = 0x2; public final static short RIGHT = 0x3; public final static short FILL = 0x4; public final static short JUSTIFY = 0x5; public final static short CENTER_SELECTION = 0x6; // vertical alignment public final static short VERTICAL_TOP = 0x0; public final static short VERTICAL_CENTER = 0x1; public final static short VERTICAL_BOTTOM = 0x2; public final static short VERTICAL_JUSTIFY = 0x3; // fill public final static short NO_FILL = 0 ; public final static short SOLID_FILL = 1 ; public final static short FINE_DOTS = 2 ; public final static short ALT_BARS = 3 ; public final static short SPARSE_DOTS = 4 ; public final static short THICK_HORZ_BANDS = 5 ; public final static short THICK_VERT_BANDS = 6 ; public final static short THICK_BACKWARD_DIAG = 7 ; public final static short THICK_FORWARD_DIAG = 8 ; public final static short BIG_SPOTS = 9 ; public final static short BRICKS = 10 ; public final static short THIN_HORZ_BANDS = 11 ; public final static short THIN_VERT_BANDS = 12 ; public final static short THIN_BACKWARD_DIAG = 13 ; public final static short THIN_FORWARD_DIAG = 14 ; public final static short SQUARES = 15 ; public final static short DIAMONDS = 16 ; // fields in BOTH style and Cell XF records private short field_1_font_index; // not bit-mapped private short field_2_format_index; // not bit-mapped // field_3_cell_options bit map static final private BitField _locked = new BitField(0x0001); static final private BitField _hidden = new BitField(0x0002); static final private BitField _xf_type = new BitField(0x0004); static final private BitField _123_prefix = new BitField(0x0008); static final private BitField _parent_index = new BitField(0xFFF0); private short field_3_cell_options; // field_4_alignment_options bit map static final private BitField _alignment = new BitField(0x0007); static final private BitField _wrap_text = new BitField(0x0008); static final private BitField _vertical_alignment = new BitField(0x0070); static final private BitField _justify_last = new BitField(0x0080); static final private BitField _rotation = new BitField(0xFF00); private short field_4_alignment_options; // field_5_indention_options static final private BitField _indent = new BitField(0x000F); static final private BitField _shrink_to_fit = new BitField(0x0010); static final private BitField _merge_cells = new BitField(0x0020); static final private BitField _reading_order = new BitField(0x00C0); // apparently bits 8 and 9 are unused static final private BitField _indent_not_parent_format = new BitField(0x0400); static final private BitField _indent_not_parent_font = new BitField(0x0800); static final private BitField _indent_not_parent_alignment = new BitField(0x1000); static final private BitField _indent_not_parent_border = new BitField(0x2000); static final private BitField _indent_not_parent_pattern = new BitField(0x4000); static final private BitField _indent_not_parent_cell_options = new BitField(0x8000); private short field_5_indention_options; // field_6_border_options bit map static final private BitField _border_left = new BitField(0x000F); static final private BitField _border_right = new BitField(0x00F0); static final private BitField _border_top = new BitField(0x0F00); static final private BitField _border_bottom = new BitField(0xF000); private short field_6_border_options; // all three of the following attributes are palette options // field_7_palette_options bit map static final private BitField _left_border_palette_idx = new BitField(0x007F); static final private BitField _right_border_palette_idx = new BitField(0x3F80); static final private BitField _diag = new BitField(0xC000); private short field_7_palette_options; // field_8_adtl_palette_options bit map static final private BitField _top_border_palette_idx = new BitField(0x0000007F); static final private BitField _bottom_border_palette_idx = new BitField(0x00003F80); static final private BitField _adtl_diag = new BitField(0x001fc000); static final private BitField _adtl_diag_line_style = new BitField(0x01e00000); // apparently bit 25 is unused static final private BitField _adtl_fill_pattern = new BitField(0xfc000000); private int field_8_adtl_palette_options; // additional to avoid 2 // field_9_fill_palette_options bit map static final private BitField _fill_foreground = new BitField(0x007F); static final private BitField _fill_background = new BitField(0x3f80); // apparently bits 15 and 14 are unused private short field_9_fill_palette_options; /** * Constructor ExtendedFormatRecord * * */ public ExtendedFormatRecord() { } /** * Constructs an ExtendedFormat record and sets its fields appropriately. * * @param id id must be 0xE0 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 ExtendedFormatRecord(short id, short size, byte [] data) { super(id, size, data); } /** * Constructs an ExtendedFormat record and sets its fields appropriately. * * @param id id must be 0xE0 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 ExtendedFormatRecord(short id, short size, byte [] data, int offset) { super(id, size, data, offset); } protected void validateSid(short id) { if (id != sid) { throw new RecordFormatException("NOT A EXTENDED FORMAT RECORD"); } } protected void fillFields(byte [] data, short size, int offset) { field_1_font_index = LittleEndian.getShort(data, 0 + offset); field_2_format_index = LittleEndian.getShort(data, 2 + offset); field_3_cell_options = LittleEndian.getShort(data, 4 + offset); field_4_alignment_options = LittleEndian.getShort(data, 6 + offset); field_5_indention_options = LittleEndian.getShort(data, 8 + offset); field_6_border_options = LittleEndian.getShort(data, 10 + offset); field_7_palette_options = LittleEndian.getShort(data, 12 + offset); field_8_adtl_palette_options = LittleEndian.getInt(data, 14 + offset); field_9_fill_palette_options = LittleEndian.getShort(data, 18 + offset); } /** * set the index to the FONT record (which font to use 0 based) * * * @param index to the font * @see org.apache.poi.hssf.record.FontRecord */ public void setFontIndex(short index) { field_1_font_index = index; } /** * set the index to the Format record (which FORMAT to use 0-based) * * * @param index to the format record * @see org.apache.poi.hssf.record.FormatRecord */ public void setFormatIndex(short index) { field_2_format_index = index; } /** * sets the options bitmask - you can also use corresponding option bit setters * (see other methods that reference this one) * * * @param options bitmask to set * */ public void setCellOptions(short options) { field_3_cell_options = options; } // These are the bit fields in cell options /** * set whether the cell is locked or not * * * @param locked - if the cell is locked * @see #setCellOptions(short) */ public void setLocked(boolean locked) { field_3_cell_options = _locked.setShortBoolean(field_3_cell_options, locked); } /** * set whether the cell is hidden or not * * * @param hidden - if the cell is hidden * @see #setCellOptions(short) */ public void setHidden(boolean hidden) { field_3_cell_options = _hidden.setShortBoolean(field_3_cell_options, hidden); } /** * set whether the cell is a cell or style XFRecord * * * @param type - cell or style (0/1) * @see #XF_STYLE * @see #XF_CELL * @see #setCellOptions(short) */ public void setXFType(short type) { field_3_cell_options = _xf_type.setShortValue(field_3_cell_options, type); } /** * set some old holdover from lotus 123. Who cares, its all over for Lotus. * RIP Lotus. * * @param prefix - the lotus thing to set. * @see #setCellOptions(short) */ public void set123Prefix(boolean prefix) { field_3_cell_options = _123_prefix.setShortBoolean(field_3_cell_options, prefix); } // present in both but NULL except in cell records /** * for cell XF types this is the parent style (usually 0/normal). For * style this should be NULL. * * @param parent index of parent XF * @see #NULL * @see #setCellOptions(short) */ public void setParentIndex(short parent) { field_3_cell_options = _parent_index.setShortValue(field_3_cell_options, parent); } // end bitfields in cell options /** * set the alignment options bitmask. See corresponding bitsetter methods * that reference this one. * * * @param options - the bitmask to set */ public void setAlignmentOptions(short options) { field_4_alignment_options = options; } /** * set the horizontal alignment of the cell. * * * @param align - how to align the cell (see constants) * @see #GENERAL * @see #LEFT * @see #CENTER * @see #RIGHT * @see #FILL * @see #JUSTIFY * @see #CENTER_SELECTION * @see #setAlignmentOptions(short) */ public void setAlignment(short align) { field_4_alignment_options = _alignment.setShortValue(field_4_alignment_options, align); } /** * set whether to wrap the text in the cell * * * @param wrapped - whether or not to wrap the cell text * @see #setAlignmentOptions(short) */ public void setWrapText(boolean wrapped) { field_4_alignment_options = _wrap_text.setShortBoolean(field_4_alignment_options, wrapped); } /** * set the vertical alignment of text in the cell * * * @param align where to align the text * @see #VERTICAL_TOP * @see #VERTICAL_CENTER * @see #VERTICAL_BOTTOM * @see #VERTICAL_JUSTIFY * * @see #setAlignmentOptions(short) */ public void setVerticalAlignment(short align) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -