[]
        
(Showing Draft Content)

IBackgroundPictures

Interface IBackgroundPictures

All Superinterfaces:
Iterable<IBackgroundPicture>

public interface IBackgroundPictures extends Iterable<IBackgroundPicture>
Represents the collection of background pictures on a worksheet or chart sheet.

This interface provides access to the IBackgroundPicture objects associated with a sheet, including retrieving pictures by index or name and obtaining the total number of pictures in the collection.


 IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
 try (InputStream stream = createSampleImageStream()) {
     IBackgroundPicture createdPicture = backgroundPictures.addPicture(stream, ImageType.PNG, 12, 18, 120, 80);
     createdPicture.setName("Watermark");
 }
 int count = backgroundPictures.getCount();
 IBackgroundPicture picture = backgroundPictures.get(0);
 IBackgroundPicture namedPicture = backgroundPictures.get("Watermark");
 
  • Method Details

    • get

      IBackgroundPicture get(int index)
      Returns a single background picture from the collection.

      Use the index parameter to retrieve a background picture by its position in the IBackgroundPictures collection.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       int count = backgroundPictures.getCount();
       if (count > 0) {
           IBackgroundPicture picture = backgroundPictures.get(0);
       }
       
      Parameters:
      index - The zero-based index of the background picture in the collection.
      Returns:
      The IBackgroundPicture at the specified index.
    • get

      Returns a single object from a collection by name.

      Use this method to retrieve an IBackgroundPicture from the current IBackgroundPictures collection by its name.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       try (InputStream stream = createSampleImageStream()) {
           backgroundPictures.addPicture(stream, ImageType.PNG, 12, 18, 120, 80).setName("Logo");
       }
       IBackgroundPicture picture = backgroundPictures.get("Logo");
       
      Parameters:
      name - The String name of the object to retrieve.
      Returns:
      The IBackgroundPicture object with the specified name.
    • getCount

      int getCount()
      Returns the number of objects in the collection.

      Gets the number of IBackgroundPicture objects in this background picture collection for the worksheet.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       try {
           String imagePath = java.nio.file.Paths.get("Users", "DefaultApps", "Documents", "logo.png").toString();
           backgroundPictures.addPicture(imagePath, 12, 18, 160, 90);
       } catch (IOException e) {
           throw new IllegalStateException("Unable to add sample background picture from file", e);
       }
       int count = backgroundPictures.getCount();
       
      Returns:
      The number of objects in the collection.
    • addPicture

      IBackgroundPicture addPicture(String filename, double left, double top, double width, double height) throws IOException
      Creates a background picture from an existing file and returns the IBackgroundPicture object that represents the new background picture.

      The picture is positioned and sized by the destination rectangle specified in points relative to the upper-left corner of the document.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       try {
           String imagePath = java.nio.file.Paths.get("Users", "DefaultApps", "Documents", "logo.png").toString();
           IBackgroundPicture picture = backgroundPictures.addPicture(imagePath, 12, 18, 160, 90);
       } catch (IOException e) {
           throw new IllegalStateException("Unable to add sample background picture from file", e);
       }
       
      Parameters:
      filename - The file from which the background picture is created.
      left - The position, in points, of the upper-left corner of the destination rectangle relative to the upper-left corner of the document.
      top - The position, in points, of the upper-left corner of the destination rectangle relative to the top of the document.
      width - The width of the destination rectangle, in points.
      height - The height of the destination rectangle, in points.
      Returns:
      The IBackgroundPicture object that represents the new background picture.
      Throws:
      IOException - if the specified file cannot be read.
    • addPicture

      IBackgroundPicture addPicture(InputStream stream, ImageType type, double left, double top, double width, double height) throws IOException
      Creates a background picture from an existing stream and returns the newly created IBackgroundPicture object.

      Use this method to add a background picture at the specified position and size in points. The left and top parameters specify the upper-left corner of the destination rectangle relative to the upper-left corner of the document.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       IBackgroundPicture picture = null;
       try (InputStream stream = createSampleImageStream()) {
           picture = backgroundPictures.addPicture(stream, ImageType.PNG, 12, 18, 120, 80);
           picture.setBackgroundImageLayout(ImageLayout.Center);
       } catch (IOException e) {
           throw new IllegalStateException("Unable to add sample background picture from stream", e);
       }
       
      Parameters:
      stream - The stream from which the background picture is created.
      type - Specifies the image type of the stream.
      left - The position, in points, of the upper-left corner of the destination rectangle relative to the upper-left corner of the document.
      top - The position, in points, of the upper-left corner of the destination rectangle relative to the top of the document.
      width - The width of the destination rectangle, in points.
      height - The height of the destination rectangle, in points.
      Returns:
      The newly created IBackgroundPicture object.
      Throws:
      IOException - if an I/O error occurs while reading the image stream.
    • addPictureInPixel

      IBackgroundPicture addPictureInPixel(String filename, double left, double top, double width, double height) throws IOException
      Creates a background picture from an existing file and returns the IBackgroundPicture object that represents the new background picture.

      The picture is positioned and sized by the destination rectangle specified in pixels relative to the upper-left corner of the document.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       try {
           String imagePath = java.nio.file.Paths.get("Users", "DefaultApps", "Documents", "logo.png").toString();
           IBackgroundPicture picture = backgroundPictures.addPictureInPixel(imagePath, 12, 18, 160, 90);
       } catch (IOException e) {
           throw new IllegalStateException("Unable to add sample background picture in pixel from file", e);
       }
       
      Parameters:
      filename - The file from which the background picture is created.
      left - The position, in pixels, of the upper-left corner of the destination rectangle relative to the upper-left corner of the document.
      top - The position, in pixels, of the upper-left corner of the destination rectangle relative to the top of the document.
      width - The width of the destination rectangle, in pixels.
      height - The height of the destination rectangle, in pixels.
      Returns:
      The IBackgroundPicture object that represents the new background picture.
      Throws:
      IOException - if the specified file cannot be read.
    • addPictureInPixel

      IBackgroundPicture addPictureInPixel(InputStream stream, ImageType type, double left, double top, double width, double height) throws IOException
      Creates a background picture from an existing stream and returns the IBackgroundPicture object that represents the new background picture.

      The picture is positioned and sized by the destination rectangle specified in pixels relative to the upper-left corner of the document.

      
       IBackgroundPictures backgroundPictures = worksheet.getBackgroundPictures();
       IBackgroundPicture picture = null;
       try (InputStream stream = createSampleImageStream()) {
           picture = backgroundPictures.addPictureInPixel(stream, ImageType.PNG, 12, 18, 160, 90);
       } catch (IOException e) {
           throw new IllegalStateException("Unable to add sample background picture in pixel from stream", e);
       }
       
      Parameters:
      stream - The stream from which the background picture is created.
      type - Specifies the type of picture to create.
      left - The position, in pixels, of the upper-left corner of the destination rectangle relative to the upper-left corner of the document.
      top - The position, in pixels, of the upper-left corner of the destination rectangle relative to the top of the document.
      width - The width of the destination rectangle, in pixels.
      height - The height of the destination rectangle, in pixels.
      Returns:
      The IBackgroundPicture object that represents the new background picture.
      Throws:
      IOException - if an I/O error occurs while reading the image stream.