Lägg till en bild i en Excel kommentar

Lägg till bild i Excel-kommentar med Microsoft Excel

Med Microsoft Excel 2007 är det möjligt att ha en bild som bakgrund till en cellkommentar. I Excel 2007 görs detta (förutsatt att kommentaren redan har lagts till) på följande sätt:

  1. Högerklicka på cellen som innehåller kommentaren.
  2. Välj Visa/dölj kommentarer och rensa eventuell text från kommentaren.
  3. Klicka på kommentarens kant för att markera den.
  4. Välj Format, sedan Kommentar.
  5. På fliken Färger och linjer klickar du på pilen för Färg.
  6. Klicka på Fyllnings effekter.
  7. På fliken Bild klickar du på Välj bild.
  8. Hitta och markera bilden
  9. Klicka på OK.

Lägg till bild i Excel-kommentar med Aspose.Cells

Aspose.Cells tillhandahåller denna värdefulla funktion.

Provkoden nedan skapar en XLSX-fil från grunden och lägger till en kommentar med en bild som bakgrund till cellen A1.

Efter att ha kört koden har A1 en kommentar med en bakgrundsbild.

Utgångsfilen

todo:image_alt_text

Exempelkod

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