Class PictureAnchor


  • public class PictureAnchor
    extends Object
    Defines the positioning of an image within a worksheet. Supports both one-cell and two-cell anchoring.

    One-cell anchor: Image is positioned at a cell with explicit size (width/height). Two-cell anchor: Image spans from one cell to another, resizing with cells.

    • Field Detail

      • EMU_PER_PIXEL

        public static final int EMU_PER_PIXEL
        EMUs (English Metric Units) per pixel at 96 DPI.
        See Also:
        Constant Field Values
    • Method Detail

      • oneCellAnchor

        public static PictureAnchor oneCellAnchor​(int row,
                                                  int col,
                                                  int widthPx,
                                                  int heightPx)
        Create a one-cell anchor with explicit size in pixels.
        Parameters:
        row - Zero-based row number
        col - Zero-based column number
        widthPx - Image width in pixels
        heightPx - Image height in pixels
        Returns:
        A new PictureAnchor configured for one-cell anchoring
      • oneCellAnchor

        public static PictureAnchor oneCellAnchor​(int row,
                                                  int col,
                                                  int colOffPx,
                                                  int rowOffPx,
                                                  int widthPx,
                                                  int heightPx)
        Create a one-cell anchor with offset and explicit size in pixels.
        Parameters:
        row - Zero-based row number
        col - Zero-based column number
        colOffPx - Column offset in pixels from the left edge of the cell
        rowOffPx - Row offset in pixels from the top edge of the cell
        widthPx - Image width in pixels
        heightPx - Image height in pixels
        Returns:
        A new PictureAnchor configured for one-cell anchoring with offset
      • twoCellAnchor

        public static PictureAnchor twoCellAnchor​(int fromRow,
                                                  int fromCol,
                                                  int toRow,
                                                  int toCol)
        Create a two-cell anchor spanning from one cell to another.
        Parameters:
        fromRow - Starting row (zero-based)
        fromCol - Starting column (zero-based)
        toRow - Ending row (zero-based, exclusive - image ends at top of this row)
        toCol - Ending column (zero-based, exclusive - image ends at left of this column)
        Returns:
        A new PictureAnchor configured for two-cell anchoring
      • twoCellAnchor

        public static PictureAnchor twoCellAnchor​(int fromRow,
                                                  int fromCol,
                                                  int fromColOffPx,
                                                  int fromRowOffPx,
                                                  int toRow,
                                                  int toCol,
                                                  int toColOffPx,
                                                  int toRowOffPx)
        Create a two-cell anchor with offsets.
        Parameters:
        fromRow - Starting row (zero-based)
        fromCol - Starting column (zero-based)
        fromColOffPx - Starting column offset in pixels
        fromRowOffPx - Starting row offset in pixels
        toRow - Ending row (zero-based)
        toCol - Ending column (zero-based)
        toColOffPx - Ending column offset in pixels
        toRowOffPx - Ending row offset in pixels
        Returns:
        A new PictureAnchor configured for two-cell anchoring with offsets
      • isTwoCellAnchor

        public boolean isTwoCellAnchor()
        Check if this anchor is a two-cell anchor.
        Returns:
        true if two-cell anchor, false if one-cell anchor
      • getWidthEmu

        public Long getWidthEmu()
        Get width in EMUs (for one-cell anchors).
      • getHeightEmu

        public Long getHeightEmu()
        Get height in EMUs (for one-cell anchors).