[]
        
(Showing Draft Content)

CellPicture

Class CellPicture

java.lang.Object
com.grapecity.documents.excel.CellPicture

public class CellPicture extends Object
Represents a picture embedded in a cell (Picture-In-Cell).

 Workbook workbook = new Workbook();
 IWorksheet worksheet = workbook.getActiveSheet();
 byte[] imageBytes = java.util.Base64.getDecoder().decode(
         "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aF9sAAAAASUVORK5CYII=");
 CellPicture picture = new CellPicture(imageBytes, "Company logo");
 worksheet.getRange("A1").setCellPicture(picture);
 CellPicture savedPicture = worksheet.getRange("A1").getCellPicture();
 String altText = savedPicture.getAltText();
 
  • Constructor Details

    • CellPicture

      public CellPicture(byte[] imageData)
      Initializes a new instance of the CellPicture class with the specified image data. The provided array is copied, so subsequent changes to the input array do not affect this instance.
      Parameters:
      imageData - The image binary data. Supported types: PNG, JPG, GIF, BMP, SVG.
    • CellPicture

      public CellPicture(byte[] imageData, String altText)
      Initializes a new instance of the CellPicture class with the specified image data and alt text. The provided array is copied, so subsequent changes to the input array do not affect this instance.
      Parameters:
      imageData - The image binary data. Supported types: PNG, JPG, GIF, BMP, SVG.
      altText - The alt text of the picture.
  • Method Details

    • getImageData

      public byte[] getImageData()
      Gets a copy of the image binary data.
      
       byte[] imageBytes = java.util.Base64.getDecoder().decode(
               "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aF9sAAAAASUVORK5CYII=");
       worksheet.getRange("A1").setCellPicture(new CellPicture(imageBytes, "Company logo"));
       CellPicture picture = worksheet.getRange("A1").getCellPicture();
       byte[] copiedImageData = picture.getImageData();
       
      Returns:
      A copy of the image binary data, or null if no image data exists. Modifying the returned array does not affect the data stored in this CellPicture.
    • getAltText

      public String getAltText()
      Gets the alt text of the picture. The alt text is also used as the display value for Filter and Sort.
      
       byte[] imageBytes = java.util.Base64.getDecoder().decode(
               "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aF9sAAAAASUVORK5CYII=");
       worksheet.getRange("A1").setCellPicture(new CellPicture(imageBytes, "Company logo"));
       CellPicture picture = worksheet.getRange("A1").getCellPicture();
       String altText = picture.getAltText();
       
      Returns:
      The alt text of the picture.
    • setAltText

      public void setAltText(String altText)
      Sets the alt text of the picture. After modification, it must be reassigned to IRange.setCellPicture(CellPicture) to take effect.
      
       java.util.function.Supplier<byte[]> imageDataProvider = () -> java.util.Base64.getDecoder().decode(
               "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aF9sAAAAASUVORK5CYII=");
       byte[] imageBytes = imageDataProvider.get();
       CellPicture picture = new CellPicture(imageBytes);
       picture.setAltText("Company logo");
       worksheet.getRange("A1").setCellPicture(picture);
       
      Parameters:
      altText - The alt text of the picture.