Excelコメントに画像を追加
Microsoft Excelでは、スプレッドシートの外観や操作を大幅にカスタマイズすることができます。コメントに背景画像を追加することも可能です。
コメントは、式の詳細、値の由来、またはレビュアーからの質問など、さまざまなことを記録するためにセルに追加されます。背景画像を追加することは美的な選択肢であるか、ブランディングを強化するために使用することもあります。
Microsoft ExcelでExcelコメントに画像を追加
Microsoft Excel 2007では、セルのコメントにイメージを背景として追加することができます。Excel 2007では、次のように行います(コメントが既に追加されていると仮定して):
- コメントを追加済みのセルを右クリックします。
- コメントの表示/非表示を選択し、コメントのテキストを消去します。
- コメントの境界線をクリックして選択します。
- フォーマット、コメントの順に選択します。
- 色と線タブで、色の矢印をクリックします。
- 塗りつぶしの効果をクリックします。
- 画像タブで、画像の選択をクリックします。
- 画像を探して選択します
- OK をクリックします。
Aspose.Cells を使用して Excel コメントに画像を追加する
Aspose.Cells はこの貴重な機能を提供します。
以下のサンプルコードは、ゼロから XLSX ファイルを作成し、セル A1 に画像を背景としたコメントを追加します。
コードを実行した後、A1 に背景画像付きのコメントが表示されます。
出力ファイル
サンプルコード
// 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"); |