Aggiungi un'immagine a un commento di Excel

Aggiungi immagine a Excel Comment con Microsoft Excel

Con Microsoft Excel 2007, è possibile avere un’immagine come sfondo di un commento di cella. In Excel 2007, ciò viene eseguito (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. ScegliereMostra/Nascondi commenti e cancella qualsiasi testo dal commento.
  3. Fare clic sul bordo del commento per selezionarlo.
  4. ScegliereFormato , poiCommento.
  5. Nella scheda Colori e linee, fare clic sulla freccia perColore.
  6. ClicEffetti di riempimento.
  7. Nella scheda Immagine fare clic suSeleziona Immagine.
  8. Individua e seleziona l’immagine
  9. ClicOK.

Aggiungi immagine al commento Excel con Aspose.Cells

Aspose.Cells fornisce questa preziosa caratteristica.

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

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

Il file di output

cose da fare:immagine_alt_testo

Codice d’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");