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

📄 drawing.java

📁 JAVA读取excel表格里的数据,与jdbc功能相当,是一个包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  {
    referenceCount = r;
  }

  /**
   * Accessor for the column of this drawing
   *
   * @return the column
   */
  public double getX()
  {
    if (!initialized)
    {
      initialize();
    }
    return x;
  }

  /**
   * Sets the column position of this drawing
   *
   * @param x the column
   */
  public void setX(double x)
  {
    if (origin == Origin.READ)
    {
      if (!initialized)
      {
        initialize();
      }
      origin = Origin.READ_WRITE;
    }

    this.x = x;
  }

  /**
   * Accessor for the row of this drawing
   *
   * @return the row
   */
  public double getY()
  {
    if (!initialized)
    {
      initialize();
    }

    return y;
  }

  /**
   * Accessor for the row of the drawing
   *
   * @param y the row
   */
  public void setY(double y)
  {
    if (origin == Origin.READ)
    {
      if (!initialized)
      {
        initialize();
      }
      origin = Origin.READ_WRITE;
    }

    this.y = y;
  }


  /**
   * Accessor for the width of this drawing
   *
   * @return the number of columns spanned by this image
   */
  public double getWidth()
  {
    if (!initialized)
    {
      initialize();
    }

    return width;
  }

  /**
   * Accessor for the width
   *
   * @param w the number of columns to span
   */
  public void setWidth(double w)
  {
    if (origin == Origin.READ)
    {
      if (!initialized)
      {
        initialize();
      }
      origin = Origin.READ_WRITE;
    }

    width = w;
  }

  /**
   * Accessor for the height of this drawing
   *
   * @return the number of rows spanned by this image
   */
  public double getHeight()
  {
    if (!initialized)
    {
      initialize();
    }

    return height;
  }

  /**
   * Accessor for the height of this drawing
   *
   * @param h the number of rows spanned by this image
   */
  public void setHeight(double h)
  {
    if (origin == Origin.READ)
    {
      if (!initialized)
      {
        initialize();
      }
      origin = Origin.READ_WRITE;
    }

    height = h;
  }


  /**
   * Gets the SpContainer that was read in
   *
   * @return the read sp container
   */
  private EscherContainer getReadSpContainer()
  {
    if (!initialized)
    {
      initialize();
    }

    return readSpContainer;
  }

  /**
   * Accessor for the image data
   *
   * @return the image data
   */
  public byte[] getImageData()
  {
    Assert.verify(origin == Origin.READ || origin == Origin.READ_WRITE);

    if (!initialized)
    {
      initialize();
    }

    return drawingGroup.getImageData(blipId);
  }

  /**
   * Accessor for the image data
   *
   * @return the image data
   */
  public byte[] getImageBytes() throws IOException
  {
    if (origin == Origin.READ || origin == Origin.READ_WRITE)
    {
      return getImageData();
    }

    Assert.verify(origin == Origin.WRITE);

    if (imageFile == null)
    {
      Assert.verify(imageData != null);
      return imageData;
    }

    byte[] data = new byte[(int) imageFile.length()];
    FileInputStream fis = new FileInputStream(imageFile);
    fis.read(data, 0, data.length);
    fis.close();
    return data;
  }

  /**
   * Accessor for the type
   *
   * @return the type
   */
  public ShapeType getType()
  {
    return type;
  }

  /**
   * Writes any other records associated with this drawing group object
   *
   * @param outputFile the output file
   * @exception IOException
   */
  public void writeAdditionalRecords(File outputFile) throws IOException
  {
    if (origin == Origin.READ)
    {
      outputFile.write(objRecord);
      return;
    }

    // Create the obj record
    ObjRecord objrec = new ObjRecord(objectId,
                                     ObjRecord.PICTURE);
    outputFile.write(objrec);
  }

  /**
   * Writes any records that need to be written after all the drawing group
   * objects have been written
   * Does nothing here
   *
   * @param outputFile the output file
   */
  public void writeTailRecords(File outputFile) throws IOException
  {
    // does nothing
  }

  /**
   * Interface method
   *
   * @return the column number at which the image is positioned
   */
  public double getColumn()
  {
    return getX();
  }

  /**
   * Interface method
   *
   * @return the row number at which the image is positions
   */
  public double getRow()
  {
    return getY();
  }

  /**
   * Accessor for the first drawing on the sheet.  This is used when
   * copying unmodified sheets to indicate that this drawing contains
   * the first time Escher gubbins
   *
   * @return TRUE if this MSORecord is the first drawing on the sheet
   */
  public boolean isFirst()
  {
    return msoDrawingRecord.isFirst();
  }

  /**
   * Queries whether this object is a form object.  Form objects have their
   * drawings records spread over TXO and CONTINUE records and
   * require special handling
   *
   * @return TRUE if this is a form object, FALSE otherwise
   */
  public boolean isFormObject()
  {
    return false;
  }

  /**
   * Removes a row
   *
   * @param r the row to be removed
   */
  public void removeRow(int r)
  {
    if (y > r)
    {
      setY(r);
    }
  }

  /**
   * Accessor for the image dimensions.  See technotes for Bill's explanation
   * of the calculation logic
   *
   * @return  approximate drawing size in pixels
   */
  private double getWidthInPoints()
  {
    if (sheet == null)
    {
      logger.warn("calculating image width:  sheet is null");
      return 0;
    }

    // The start and end row numbers
    int firstCol = (int) x;
    int lastCol = (int) Math.ceil(x + width) - 1;

    // **** MAGIC NUMBER ALERT ***
    // multiply the point size of the font by 0.59 to give the point size
    // I know of no explanation for this yet, other than that it seems to
    // give the right answer

    // Get the width of the image within the first col, allowing for 
    // fractional offsets
    CellView cellView = sheet.getColumnView(firstCol);
    int firstColWidth = cellView.getSize();
    double firstColImageWidth =  (1 - (x - firstCol)) * firstColWidth;
    double pointSize = (cellView.getFormat() != null) ? 
      cellView.getFormat().getFont().getPointSize() : DEFAULT_FONT_SIZE;
    double firstColWidthInPoints = firstColImageWidth * 0.59 * pointSize / 256;

    // Get the height of the image within the last row, allowing for
    // fractional offsets
    int lastColWidth = 0;
    double lastColImageWidth = 0;
    double lastColWidthInPoints = 0;
    if (lastCol != firstCol)
    {
      cellView = sheet.getColumnView(lastCol);
      lastColWidth = cellView.getSize();
      lastColImageWidth = (x + width - lastCol) * lastColWidth;
      pointSize = (cellView.getFormat() != null) ? 
        cellView.getFormat().getFont().getPointSize() : DEFAULT_FONT_SIZE;
      lastColWidthInPoints = lastColImageWidth * 0.59 * pointSize / 256;
    }
    
    // Now get all the columns in between
    double width = 0;
    for (int i = 0 ; i < lastCol - firstCol - 1 ; i++)
    {
      cellView = sheet.getColumnView(firstCol + 1 +i);
      pointSize = (cellView.getFormat() != null) ? 
        cellView.getFormat().getFont().getPointSize() : DEFAULT_FONT_SIZE;
      width += cellView.getSize() * 0.59 * pointSize / 256;
    }

    // Add on the first and last row contributions to get the height in twips
    double widthInPoints = width + 
      firstColWidthInPoints + lastColWidthInPoints;
    
    return widthInPoints;
  }

  /**
   * Accessor for the image dimensions.  See technotes for Bill's explanation
   * of the calculation logic
   *
   * @return approximate drawing size in pixels
   */
  private double getHeightInPoints()
  {
    if (sheet == null)
    {
      logger.warn("calculating image height:  sheet is null");
      return 0;
    }

    // The start and end row numbers
    int firstRow = (int) y;
    int lastRow = (int) Math.ceil(y + height) - 1;

    // Get the height of the image within the first row, allowing for 
    // fractional offsets
    int firstRowHeight = sheet.getRowView(firstRow).getSize();
    double firstRowImageHeight =  (1 - (y - firstRow)) * firstRowHeight;

    // Get the height of the image within the last row, allowing for
    // fractional offsets
    int lastRowHeight = 0;
    double lastRowImageHeight = 0;
    if (lastRow != firstRow)
    {
      lastRowHeight = sheet.getRowView(lastRow).getSize();
      lastRowImageHeight = (y + height - lastRow) * lastRowHeight;
    }
    
    // Now get all the rows in between
    double height = 0;
    for (int i = 0 ; i < lastRow - firstRow - 1 ; i++)
    {
      height += sheet.getRowView(firstRow + 1 + i).getSize();
    }

    // Add on the first and last row contributions to get the height in twips
    double heightInTwips = height + firstRowHeight + lastRowHeight;
    
    // Now divide by the magic number to converts twips into pixels and 
    // return the value
    double heightInPoints = heightInTwips / 20.0;

    return heightInPoints;
  }

  /**
   * Get the width of this image as rendered within Excel
   *
   * @param unit the unit of measurement
   * @return the width of the image within Excel
   */
  public double getWidth(LengthUnit unit)
  {
    double widthInPoints = getWidthInPoints();
    return widthInPoints * LengthConverter.getConversionFactor
      (LengthUnit.POINTS, unit);
  }

  /**
   * Get the height of this image as rendered within Excel
   *
   * @param unit the unit of measurement
   * @return the height of the image within Excel
   */
  public double getHeight(LengthUnit unit)
  {
    double heightInPoints = getHeightInPoints();
    return heightInPoints * LengthConverter.getConversionFactor
      (LengthUnit.POINTS, unit);
  }

  /**
   * Gets the width of the image.  Note that this is the width of the 
   * underlying image, and does not take into account any size manipulations
   * that may have occurred when the image was added into Excel
   *
   * @return the image width in pixels
   */
  public int getImageWidth()
  {
    return getPngReader().getWidth();
  }

  /**
   * Gets the height of the image.  Note that this is the height of the 
   * underlying image, and does not take into account any size manipulations
   * that may have occurred when the image was added into Excel
   *
   * @return the image width in pixels
   */
  public int getImageHeight()
  {
    return getPngReader().getHeight();
  }


  /**
   * Gets the horizontal resolution of the image, if that information
   * is available.
   *
   * @return the number of dots per unit specified, if available, 0 otherwise
   */
  public double getHorizontalResolution(LengthUnit unit)
  {
    int res = getPngReader().getHorizontalResolution();
    return res / LengthConverter.getConversionFactor(LengthUnit.METRES, unit);
  }

  /**
   * Gets the vertical resolution of the image, if that information
   * is available.
   *
   * @return the number of dots per unit specified, if available, 0 otherwise
   */
  public double getVerticalResolution(LengthUnit unit)
  {
    int res = getPngReader().getVerticalResolution();
    return res / LengthConverter.getConversionFactor(LengthUnit.METRES, unit);
  }

  private PNGReader getPngReader()
  {
    if (pngReader != null)
    {
      return pngReader;
    }

    byte[] imdata = null;
    if (origin == Origin.READ || origin == Origin.READ_WRITE)
    {
      imdata = getImageData();
    }
    else
    {
      try
      {
        imdata = getImageBytes();
      }
      catch (IOException e)
      {
        logger.warn("Could not read image file");
        imdata = new byte[0];
      }
    }

    pngReader = new PNGReader(imdata);
    pngReader.read();
    return pngReader;
  }

}



⌨️ 快捷键说明

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