Agregar una imagen a un comentario de Excel

Agregar imagen a Excel Comentar con Microsoft Excel

Con Microsoft Excel 2007, es posible tener una imagen como fondo de un comentario de celda. En Excel 2007, esto se logra (suponiendo que ya se haya agregado el comentario) de esta manera:

  1. Haga clic derecho en la celda que contiene el comentario.
  2. EscogerMostrar/Ocultar comentarios y borre cualquier texto del comentario.
  3. Haga clic en el borde del comentario para seleccionarlo.
  4. EscogerFormato , despuésComentario.
  5. En la pestaña Colores y líneas, haga clic en la flecha paraColor.
  6. Hacer clicEfectos de relleno.
  7. En la pestaña Imagen, haga clic enSeleccionar imagen.
  8. Localiza y selecciona la imagen.
  9. Hacer clicDE ACUERDO.

Agregar imagen a Excel Comentar con Aspose.Cells

Aspose.Cells proporciona esta valiosa función.

El siguiente código de ejemplo crea un archivo XLSX desde cero y agrega un comentario con una imagen de fondo a la celda A1.

Después de ejecutar el código, A1 tiene un comentario con una imagen de fondo.

El archivo de salida

todo:imagen_alternativa_texto

Código de muestra

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(AddPicturetoExcelComment.class) + "articles/";
// Instantiate a Workbook
Workbook workbook = new Workbook();
// Get a reference of comments collection with the first sheet
CommentCollection comments = workbook.getWorksheets().get(0).getComments();
// Add a comment to cell A1
int commentIndex = comments.add(0, 0);
Comment comment = comments.get(commentIndex);
comment.setNote("First note.");
comment.getFont().setName("Times New Roman");
// Load/Read an image into stream
String logo_url = dataDir + "school.jpg";
// Creating the instance of the FileInputStream object to open the logo/picture in the stream
FileInputStream inFile = new FileInputStream(logo_url);
// Setting the logo/picture
byte[] picData = new byte[inFile.available()];
inFile.read(picData);
// Set image data to the shape associated with the comment
comment.getCommentShape().getFill().setImageData(picData);
// Save the workbook
workbook.save(dataDir + "APToExcelComment_out.xlsx");