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

📄 xfrecord.java

📁 一个非常有用的操作MCRSOFT EXCEL文件的工具。可以用JAVA方便的新建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    else if (fmt.getFormat() instanceof BuiltInFormat)    {      // read excel format is built in      excelFormat = (BuiltInFormat) fmt.excelFormat;      format = (BuiltInFormat) fmt.excelFormat;    }    else    {      // read excel format is user defined      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);    data[9] = (byte) 0x10;    // 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)    {    	byte lc = (byte)leftBorderColour.getValue();    	byte rc = (byte)rightBorderColour.getValue();    	byte tc = (byte)topBorderColour.getValue();    	byte bc = (byte)bottomBorderColour.getValue();    	    	data[12] = (byte)((lc & 0x7f) | ((rc & 0x01) << 7));    	data[13] = (byte)((rc & 0x7f) >> 1);    	data[14] = (byte)((tc & 0x7f) | ((bc & 0x01) << 7));    	data[15] = (byte)((bc & 0x7f) >> 1);    }    // 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    options |= indentation & 0x0f;    if (shrinkToFit)    {      options |= 0x10;    }    else    {      options &= 0xef;    }    data[8] = (byte) options;    if (biffType == biff8)    {      //      usedAttributes = 0x4 << 2;      data[9] = usedAttributes;    }    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 indentation   *   * @param i the indentation   */  protected void setXFIndentation(int i)  {    Assert.verify(!initialized);    indentation = i;  }  /**   * 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 indentation   *   * @return the indentation   */  public int getIndentation()   {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return indentation;  }  /**   * 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;  }  /**   * Accessor for whether a particular cell is locked   *   * @return TRUE if this cell is locked, FALSE otherwise   */  public boolean isLocked()  {    if (!formatInfoInitialized)    {      initializeFormatInformation();    }    return locked;  }  /**   * 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   */  protected void setXFBorder(Border b, BorderLineStyle ls, Colour c)  {    Assert.verify(!initialized);        if (c==Colour.BLACK)     {      c = Colour.PALETTE_BLACK;    }    if (b == Border.LEFT)    {      leftBorder = ls;      leftBorderColour = c;    }    else if (b == Border.RIGHT)    {      rightBorder = ls;      rightBorderColour = c;    }    else if (b == Border.TOP)    {      topBorder = ls;      topBorderColour = c;    }    else if (b == Border.BOTTOM)    {      bottomBorder = ls;      bottomBorderColour = c;    }    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)  {    return getBorderLine(border);  }  /**   * 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 getBorderLine(Border border)  {    // Don't bother with the short cut records    if (border == Border.NONE ||        border == Border.ALL)    {      return BorderLineStyle.NONE;    }    if (!formatInfoInitialized)

⌨️ 快捷键说明

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