xfrecord.java

来自「jexcelapi_2_4, JXL的API, JXL是JAVA读取EXCEL的」· Java 代码 · 共 1,348 行 · 第 1/3 页

JAVA
1,348
字号
    Assert.verify(cellFormat instanceof XFRecord);    XFRecord fmt = (XFRecord) cellFormat;    if (!fmt.formatInfoInitialized)    {      fmt.initializeFormatInformation();    }    locked       = fmt.locked;    hidden       = fmt.hidden;    align        = fmt.align;    valign       = fmt.valign;    orientation  = fmt.orientation;    wrap         = fmt.wrap;    leftBorder   = fmt.leftBorder;    rightBorder  = fmt.rightBorder;    topBorder    = fmt.topBorder;    bottomBorder = fmt.bottomBorder;    pattern      = fmt.pattern;    xfFormatType = fmt.xfFormatType;    parentFormat = fmt.parentFormat;    shrinkToFit  = fmt.shrinkToFit;    backgroundColour = fmt.backgroundColour;    // Deep copy of the font    font = new FontRecord(fmt.getFont());    // Copy the format.  Handle the case where the formula is built in    // first    if (fmt.getFormat() instanceof BuiltInFormat)    {      excelFormat = (BuiltInFormat) fmt.excelFormat;      format = (BuiltInFormat) fmt.excelFormat;    }    else    {      Assert.verify(fmt.formatInfoInitialized);      // in this case FormattingRecords should initialize the excelFormat      // field with an instance of FormatRecord      Assert.verify(fmt.excelFormat instanceof FormatRecord);      // Format is not built in, so do a deep copy      FormatRecord fr = new FormatRecord((FormatRecord) fmt.excelFormat);      // Set both format fields to be the same object, since      // FormatRecord implements all the necessary interfaces      excelFormat = fr;      format = fr;    }    biffType = biff8;    // The format info should be all OK by virtue of the deep copy    formatInfoInitialized = true;    // This format was not read in    read = false;    // Treat this as a new cell record, so set the copied flag to false    copied = false;    // The font or format indexes need to be set, so set initialized to false    initialized = false;  }  /**   * Gets the java date format for this format record   *   * @return returns the date format   */  public DateFormat getDateFormat()  {    return dateFormat;  }  /**   * Gets the java number format for this format record   *   * @return returns the number format   */  public NumberFormat getNumberFormat()  {    return numberFormat;  }  /**   * Gets the lookup number of the format record   *   * @return returns the lookup number of the format record   */  public int getFormatRecord()  {    return formatIndex;  }  /**   * Sees if this format is a date format   *   * @return TRUE if this refers to a built in date format   */  public boolean isDate()  {    return date;  }  /**   * Sees if this format is a number format   *   * @return TRUE if this refers to a built in date format   */  public boolean isNumber()  {    return number;  }  /**   * Converts the various fields into binary data.  If this object has   * been read from an Excel file rather than being requested by a user (ie.   * if the read flag is TRUE) then   * no processing takes place and the raw data is simply returned.   *   * @return the raw data for writing   */  public byte[] getData()  {    // Format rationalization process means that we always want to    // regenerate the format info - even if the spreadsheet was    // read in    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    byte[] data = new byte[20];    IntegerHelper.getTwoBytes(fontIndex, data, 0);    IntegerHelper.getTwoBytes(formatIndex, data, 2);    // Do the cell attributes    int cellAttributes = 0;    if (getLocked())    {      cellAttributes |= 0x01;    }    if (getHidden())    {      cellAttributes |= 0x02;    }    if (xfFormatType == style)    {      cellAttributes |= 0x04;      parentFormat = 0xffff;    }    cellAttributes |= (parentFormat << 4);    IntegerHelper.getTwoBytes(cellAttributes, data, 4);    int alignMask = align.getValue();    if (wrap)    {      alignMask |= 0x08;    }    alignMask |= (valign.getValue() << 4);    alignMask |= (orientation.getValue() << 8);    IntegerHelper.getTwoBytes(alignMask, data, 6);    // Set the borders    int borderMask = leftBorder.getValue();    borderMask |= (rightBorder.getValue() << 4);    borderMask |= (topBorder.getValue() << 8);    borderMask |= (bottomBorder.getValue() << 12);    IntegerHelper.getTwoBytes(borderMask, data, 10);    // Set the border palette information if border mask is non zero    // Hard code the colours to be black    if (borderMask != 0)    {      data[12] = 0x40;      data[13] = 0x20;      data[14] = 0x40;      data[15] = 0x20;    }    // Set the background pattern    IntegerHelper.getTwoBytes(pattern.getValue(), data, 16);    // Set the colour palette    int colourPaletteMask = backgroundColour.getValue();    colourPaletteMask |= (0x40 << 7);    IntegerHelper.getTwoBytes(colourPaletteMask, data, 18);    // Set the cell options    if (shrinkToFit)    {      options |= 0x10;    }    else    {      options &= 0xffef;    }    IntegerHelper.getTwoBytes(options, data, 8);    return data;  }  /**   * Accessor for the locked flag   *   * @return TRUE if this XF record locks cells, FALSE otherwise   */  protected final boolean getLocked()  {    return locked;  }  /**   * Accessor for the hidden flag   *   * @return TRUE if this XF record hides the cell, FALSE otherwise   */  protected final boolean getHidden()  {    return hidden;  }  /**   * Sets whether or not this XF record locks the cell   *   * @param l the locked flag   */  protected final void setXFLocked(boolean l)  {    locked = l;  }  /**   * Sets the cell options   *   * @param opt the cell options   */  protected final void setXFCellOptions(int opt)  {    options |= opt;  }  /**   * Sets the horizontal alignment for the data in this cell.   * This method should only be called from its writable subclass   * CellXFRecord   *   * @param a the alignment   */  protected void setXFAlignment(Alignment a)  {    Assert.verify(!initialized);    align = a;  }  /**   * Sets the shrink to fit flag   *   * @param s the shrink to fit flag   */  protected void setXFShrinkToFit(boolean s)  {    Assert.verify(!initialized);    shrinkToFit = s;  }  /**   * Gets the horizontal cell alignment   *   * @return the alignment   */  public Alignment getAlignment()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return align;  }  /**   * Gets the shrink to fit flag   *   * @return TRUE if this format is shrink to fit, FALSE otherise   */  public boolean isShrinkToFit()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return shrinkToFit;  }  /**   * Gets the vertical cell alignment   *   * @return the alignment   */  public VerticalAlignment getVerticalAlignment()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return valign;  }  /**   * Gets the orientation   *   * @return the orientation   */  public Orientation getOrientation()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return orientation;  }  /**   * Sets the horizontal alignment for the data in this cell.   * This method should only be called from its writable subclass   * CellXFRecord   *   * @param c the background colour   * @param p the background pattern   */  protected void setXFBackground(Colour c, Pattern p)  {    Assert.verify(!initialized);    backgroundColour = c;    pattern = p;  }  /**   * Gets the background colour used by this cell   *   * @return the foreground colour   */  public Colour getBackgroundColour()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return backgroundColour;  }  /**   * Gets the pattern used by this cell format   *   * @return the background pattern   */  public Pattern getPattern()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return pattern;  }  /**   * Sets the vertical alignment for the data in this cell   * This method should only be called from its writable subclass   * CellXFRecord   *   * @param va the vertical alignment   */  protected void setXFVerticalAlignment(VerticalAlignment va)  {    Assert.verify(!initialized);    valign = va;  }  /**   * Sets the vertical alignment for the data in this cell   * This method should only be called from its writable subclass   * CellXFRecord   *   * @param o the orientation   */  protected void setXFOrientation(Orientation o)  {    Assert.verify(!initialized);    orientation = o;  }  /**   * Sets whether the data in this cell is wrapped   * This method should only be called from its writable subclass   * CellXFRecord   *   * @param w the wrap flag   */  protected void setXFWrap(boolean w)  {    Assert.verify(!initialized);    wrap = w;  }  /**   * Gets whether or not the contents of this cell are wrapped   *   * @return TRUE if this cell's contents are wrapped, FALSE otherwise   */  public boolean getWrap()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return wrap;  }  /**   * Sets the border for this cell   * This method should only be called from its writable subclass   * CellXFRecord   *   * @param b the border   * @param ls the border line style   */

⌨️ 快捷键说明

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