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

📄 xfrecord.java

📁 一个非常有用的操作MCRSOFT EXCEL文件的工具。可以用JAVA方便的新建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    {      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;  }  /**   * 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 Colour getBorderColour(Border border)  {    // Don't bother with the short cut records    if (border == Border.NONE ||        border == Border.ALL)    {      return Colour.PALETTE_BLACK;    }    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    if (border == Border.LEFT)    {      return leftBorderColour;    }    else if (border == Border.RIGHT)    {      return rightBorderColour;    }    else if (border == Border.TOP)    {      return topBorderColour;    }    else if (border == Border.BOTTOM)    {      return bottomBorderColour;    }    return Colour.BLACK;  	  }  /**   * 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);    if (xfFormatType == cell &&        (parentFormat & 0xfff) == 0xfff)    {      // Something is screwy with the parent format - set to zero      parentFormat = 0;      logger.warn("Invalid parent format found - ignoring");    }    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 indentation    indentation = (int) (attr & 0x0F);    // 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);    int borderColourMask = IntegerHelper.getInt(data[12], data[13]);    leftBorderColour = Colour.getInternalColour(borderColourMask & 0x7f);    rightBorderColour = Colour.getInternalColour      ((borderColourMask & 0x3f80) >> 7);    borderColourMask = IntegerHelper.getInt(data[14], data[15]);    topBorderColour = Colour.getInternalColour(borderColourMask & 0x7f);    bottomBorderColour = Colour.getInternalColour      ((borderColourMask & 0x3f80) >> 7);        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()  {    // Must have its formats info initialized in order to compute the hash code    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    int hashValue = 17;    int oddPrimeNumber = 37;    // The boolean fields    hashValue = oddPrimeNumber*hashValue + (hidden ? 1:0);    hashValue = oddPrimeNumber*hashValue + (locked ? 1:0);    hashValue = oddPrimeNumber*hashValue + (wrap ? 1:0);    hashValue = oddPrimeNumber*hashValue + (shrinkToFit ? 1:0);    // The enumerations    if (xfFormatType == cell)    {      hashValue = oddPrimeNumber*hashValue + 1;    }    else if (xfFormatType == style)    {      hashValue = oddPrimeNumber*hashValue + 2;    }    hashValue = oddPrimeNumber*hashValue + (align.getValue() + 1);    hashValue = oddPrimeNumber*hashValue + (valign.getValue() + 1);    hashValue = oddPrimeNumber*hashValue + (orientation.getValue());    hashValue ^= leftBorder.getDescription().hashCode();    hashValue ^= rightBorder.getDescription().hashCode();    hashValue ^= topBorder.getDescription().hashCode();    hashValue ^= bottomBorder.getDescription().hashCode();    hashValue = oddPrimeNumber*hashValue + (leftBorderColour.getValue());    hashValue = oddPrimeNumber*hashValue + (rightBorderColour.getValue());    hashValue = oddPrimeNumber*hashValue + (topBorderColour.getValue());    hashValue = oddPrimeNumber*hashValue + (bottomBorderColour.getValue());    hashValue = oddPrimeNumber*hashValue + (backgroundColour.getValue());    hashValue = oddPrimeNumber*hashValue + (pattern.getValue() + 1);    // The integer fields    hashValue = oddPrimeNumber*hashValue + usedAttributes;    hashValue = oddPrimeNumber*hashValue + parentFormat;    hashValue = oddPrimeNumber*hashValue + fontIndex;    hashValue = oddPrimeNumber*hashValue + formatIndex;    hashValue = oddPrimeNumber*hashValue + indentation;    return hashValue;  }  /**   * 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   != xfr.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 ||        indentation != xfr.indentation)    {      return false;    }    if (leftBorder   != xfr.leftBorder  ||        rightBorder  != xfr.rightBorder ||        topBorder    != xfr.topBorder   ||        bottomBorder != xfr.bottomBorder)    {      return false;    }    if (leftBorderColour   != xfr.leftBorderColour  ||        rightBorderColour  != xfr.rightBorderColour ||        topBorderColour    != xfr.topBorderColour   ||        bottomBorderColour != xfr.bottomBorderColour)    {      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);    }  }  /**   * Sets the font object with a workbook specific clone.  Called from    * the CellValue object when the font has been identified as a statically   * shared font   */  public void setFont(FontRecord f)  {    // This style cannot be initialized, otherwise it would mean it would    // have been initialized with shared font    Assert.verify(!initialized);    font = f;  }}

⌨️ 快捷键说明

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