Excel コメントに画像を追加する

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

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

  1. コメントを含むセルを右クリックします。
  2. 選ぶコメントの表示/非表示コメントからテキストをクリアします。
  3. コメントの枠線をクリックして選択します。
  4. 選ぶフォーマット、 それからコメント.
  5. [色と線] タブで、矢印をクリックします。.
  6. クリック塗りつぶし効果.
  7. [画像] タブで、画像を選択.
  8. 画像を見つけて選択する
  9. クリックわかった.

Aspose.Cells の Excel コメントに画像を追加

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

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

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

出力ファイル

todo:画像_代替_文章

サンプルコード

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