⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xfrecord.java

📁 jexcelapi_2_4, JXL的API, JXL是JAVA读取EXCEL的开源项目
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  protected void setXFBorder(Border b, BorderLineStyle ls)  {    Assert.verify(!initialized);    if (b == Border.LEFT)    {      leftBorder = ls;    }    else if (b == Border.RIGHT)    {      rightBorder = ls;    }    else if (b == Border.TOP)    {      topBorder = ls;    }    else if (b == Border.BOTTOM)    {      bottomBorder = ls;    }    return;  }  /**   * Gets the line style for the given cell border   * If a border type of ALL or NONE is specified, then a line style of   * NONE is returned   *   * @param border the cell border we are interested in   * @return the line style of the specified border   */  public BorderLineStyle getBorder(Border border)  {    // Don't bother with the short cut records    if (border == Border.NONE ||        border == Border.ALL)    {      return BorderLineStyle.NONE;    }    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    if (border == Border.LEFT)    {      return leftBorder;    }    else if (border == Border.RIGHT)    {      return rightBorder;    }    else if (border == Border.TOP)    {      return topBorder;    }    else if (border == Border.BOTTOM)    {      return bottomBorder;    }    return BorderLineStyle.NONE;  }  /**   * Determines if this cell format has any borders at all.  Used to   * set the new borders when merging a group of cells   *   * @return TRUE if this cell has any borders, FALSE otherwise   */  public final boolean hasBorders()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    if (leftBorder   == BorderLineStyle.NONE &&        rightBorder  == BorderLineStyle.NONE &&        topBorder    == BorderLineStyle.NONE &&        bottomBorder == BorderLineStyle.NONE)    {      return false;    }    return true;  }  /**   * If this cell has not been read in from an existing Excel sheet,   * then initializes this record with the XF index passed in. Calls   * initialized on the font and format record   *   * @param pos the xf index to initialize this record with   * @param fr the containing formatting records   * @param fonts the container for the fonts   * @exception NumFormatRecordsException   */  public final void initialize(int pos, FormattingRecords fr, Fonts fonts)    throws NumFormatRecordsException  {    xfIndex = pos;    formattingRecords = fr;    // If this file has been read in or copied,    // the font and format indexes will    // already be initialized, so just set the initialized flag and    // return    if (read || copied)    {      initialized = true;      return;    }    if (!font.isInitialized())    {      fonts.addFont(font);    }    if (!format.isInitialized())    {      fr.addFormat(format);    }    fontIndex = font.getFontIndex();    formatIndex = format.getFormatIndex();    initialized = true;  }  /**   * Resets the initialize flag.  This is called by the constructor of   * WritableWorkbookImpl to reset the statically declared fonts   */  public final void uninitialize()  {    initialized = false;  }  /**   * Sets the XF index.  Called when rationalizing the XF records   * immediately prior to writing   *   * @param xfi the new xf index   */  final void setXFIndex(int xfi)  {    xfIndex = xfi;  }  /**   * Accessor for the XF index   *   * @return the XF index for this cell   */  public final int getXFIndex()  {    return xfIndex;  }  /**   * Accessor to see if this format is initialized   *   * @return TRUE if this format is initialized, FALSE otherwise   */  public final boolean isInitialized()  {    return initialized;  }  /**   * Accessor to see if this format was read in.  Used when checking merged   * cells   *   * @return TRUE if this XF record was read in, FALSE if it was generated by   *         the user API   */  public final boolean isRead()  {    return read;  }  /**   * Gets the format used by this format   *   * @return the format   */  public Format getFormat()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return excelFormat;  }  /**   * Gets the font used by this format   *   * @return the font   */  public Font getFont()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return font;  }  /**   * Initializes the internal format information from the data read in   */  private void initializeFormatInformation()  {    // Initialize the cell format string    if (formatIndex < BuiltInFormat.builtIns.length &&        BuiltInFormat.builtIns[formatIndex] != null)    {      excelFormat = BuiltInFormat.builtIns[formatIndex];    }    else    {      excelFormat = formattingRecords.getFormatRecord(formatIndex);    }    // Initialize the font    font = formattingRecords.getFonts().getFont(fontIndex);    // Initialize the cell format data from the binary record    byte[] data = getRecord().getData();    // Get the parent record    int cellAttributes = IntegerHelper.getInt(data[4], data[5]);    parentFormat = (cellAttributes & 0xfff0) >> 4;    int formatType = cellAttributes & 0x4;    xfFormatType = formatType == 0 ? cell : style;    locked = ((cellAttributes & 0x1) != 0);    hidden = ((cellAttributes & 0x2) != 0);    int alignMask = IntegerHelper.getInt(data[6], data[7]);    // Get the wrap    if ((alignMask & 0x08) != 0)    {      wrap = true;    }    // Get the horizontal alignment    align = Alignment.getAlignment(alignMask & 0x7);    // Get the vertical alignment    valign = VerticalAlignment.getAlignment((alignMask >> 4) & 0x7);    // Get the orientation    orientation = Orientation.getOrientation((alignMask >> 8) & 0xff);    int attr = IntegerHelper.getInt(data[8], data[9]);    // Get the shrink to fit flag    shrinkToFit = (attr & 0x10) != 0;    // Get the used attribute    if (biffType == biff8)    {      usedAttributes = data[9];    }    // Get the borders    int borderMask = IntegerHelper.getInt(data[10], data[11]);    leftBorder   = BorderLineStyle.getStyle(borderMask & 0x7);    rightBorder  = BorderLineStyle.getStyle((borderMask >> 4) & 0x7);    topBorder    = BorderLineStyle.getStyle((borderMask >> 8) & 0x7);    bottomBorder = BorderLineStyle.getStyle((borderMask >> 12) & 0x7);    if (biffType == biff8)    {      // Get the background pattern      int patternVal = IntegerHelper.getInt(data[16], data[17]);      pattern = Pattern.getPattern(patternVal);      // Get the background colour      int colourPaletteMask = IntegerHelper.getInt(data[18], data[19]);      backgroundColour = Colour.getInternalColour(colourPaletteMask & 0x3f);      if (backgroundColour == Colour.UNKNOWN ||          backgroundColour == Colour.DEFAULT_BACKGROUND1)      {        backgroundColour = Colour.DEFAULT_BACKGROUND;      }    }    else    {      pattern = Pattern.NONE;      backgroundColour = Colour.DEFAULT_BACKGROUND;    }    // Set the lazy initialization flag    formatInfoInitialized = true;  }  /**   * Standard hash code implementation   * @return the hash code   */  public int hashCode()  {    return 17;  }  /**   * Equals method.  This is called when comparing writable formats   * in order to prevent duplicate formats being added to the workbook   *   * @param o object to compare   * @return TRUE if the objects are equal, FALSE otherwise   */  public boolean equals(Object o)  {    if (o == this)    {      return true;    }    if (!(o instanceof XFRecord))    {      return false;    }    XFRecord xfr = (XFRecord) o;    // Both records must be writable and have their format info initialized    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    if (!xfr.formatInfoInitialized)    {      xfr.initializeFormatInformation();    }    if (xfFormatType   != xfr.xfFormatType ||        parentFormat   != parentFormat ||        locked         != xfr.locked ||        hidden         != xfr.hidden ||        usedAttributes != xfr.usedAttributes)    {      return false;    }    if (align       != xfr.align ||        valign      != xfr.valign ||        orientation != xfr.orientation ||        wrap        != xfr.wrap ||        shrinkToFit != xfr.shrinkToFit)    {      return false;    }    if (leftBorder   != xfr.leftBorder ||        rightBorder  != xfr.rightBorder ||        topBorder    != xfr.topBorder ||        bottomBorder != xfr.bottomBorder)    {      return false;    }    if (backgroundColour != xfr.backgroundColour ||        pattern          != xfr.pattern)    {      return false;    }    // Sufficient to just do shallow equals on font, format objects,    // since we are testing for the presence of clones anwyay    // Use indices rather than objects because of the rationalization    // process (which does not set the object on an XFRecord)    if (fontIndex   != xfr.fontIndex ||        formatIndex != xfr.formatIndex)    {      return false;    }    return true;  }  /**   * Sets the format index.  This is called during the rationalization process   * when some of the duplicate number formats have been removed   * @param newindex the new format index   */  void setFormatIndex(int newindex)  {    formatIndex = newindex;  }  /**   * Accessor for the font index.  Called by the FormattingRecords objects   * during the rationalization process   * @return the font index   */  int getFontIndex()  {    return fontIndex;  }  /**   * Sets the font index.  This is called during the rationalization process   * when some of the duplicate fonts have been removed   * @param newindex the new index   */  void setFontIndex(int newindex)  {    fontIndex = newindex;  }  /**   * Sets the format type and parent format from the writable subclass   * @param t the xf type   * @param pf the parent format   */  protected void setXFDetails(XFType t, int pf)  {    xfFormatType = t;    parentFormat = pf;  }  /**   * Changes the appropriate indexes during the rationalization process   * @param xfMapping the xf index re-mappings   */  void rationalize(IndexMapping xfMapping)  {    xfIndex = xfMapping.getNewIndex(xfIndex);    if (xfFormatType == cell)    {      parentFormat = xfMapping.getNewIndex(parentFormat);    }  }}

⌨️ 快捷键说明

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