Aggiungere un immagine a un commento di Excel

Aggiungi immagine al commento di Excel con Microsoft Excel

Con Microsoft Excel 2007, è possibile avere un’immagine come sfondo per un commento di cella. In Excel 2007, questo si realizza (supponendo che il commento sia già stato aggiunto) in questo modo:

  1. Fare clic con il pulsante destro del mouse sulla cella che contiene il commento.
  2. Scegliere Mostra/Nascondi commenti e cancellare eventuali testi dal commento.
  3. Fare clic sul bordo del commento per selezionarlo.
  4. Scegliere Formato, quindi Commento.
  5. Nella scheda Colori e linee, fare clic sulla freccia per Colore.
  6. Fare clic su Effetti di riempimento.
  7. Nella scheda Immagine, fare clic su Seleziona immagine.
  8. Trova e seleziona l’immagine
  9. Fai clic su OK.

Aggiungi immagine al Commento di Excel con Aspose.Cells

Aspose.Cells fornisce questa caratteristica preziosa.

Il codice di esempio di seguito crea un file XLSX da zero e aggiunge un commento con un’immagine di sfondo alla cella A1.

Dopo aver eseguito il codice, A1 ha un commento con un’immagine di sfondo.

**Il file di output

todo:image_alt_text

Codice di esempio

// 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");