Excelコメントに画像を追加

Microsoft ExcelでExcelコメントに画像を追加

Microsoft Excel 2007では、セルのコメントにイメージを背景として追加することができます。Excel 2007では、次のように行います(コメントが既に追加されていると仮定して):

  1. コメントを追加済みのセルを右クリックします。
  2. コメントの表示/非表示を選択し、コメントのテキストを消去します。
  3. コメントの境界線をクリックして選択します。
  4. フォーマットコメントの順に選択します。
  5. 色と線タブで、の矢印をクリックします。
  6. 塗りつぶしの効果をクリックします。
  7. 画像タブで、画像の選択をクリックします。
  8. 画像を探して選択します
  9. OK をクリックします。

Aspose.Cells を使用して Excel コメントに画像を追加する

Aspose.Cells はこの貴重な機能を提供します。

以下のサンプルコードは、ゼロから XLSX ファイルを作成し、セル A1 に画像を背景としたコメントを追加します。

コードを実行した後、A1 に背景画像付きのコメントが表示されます。

出力ファイル

todo:image_alt_text

サンプルコード

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