向Excel备注添加图片

使用Microsoft Excel向Excel备注中添加图片

在Microsoft Excel 2007中,可以将图像作为单元格备注的背景。在Excel 2007中,可以这样完成(假设已经添加了备注):

  1. 右键单击包含评论的单元格。
  2. 选择显示/隐藏评论并清除评论中的任何文本。 1.选择格式,然后选择注释
  3. 选择格式,然后选择评论
  4. 在“颜色和线条”选项卡上,单击“颜色”的箭头。 1.单击图片选项卡。
  5. 在“图片”选项卡上,单击选择图片
  6. 定位并选择图片
  7. 点击确定

向Excel评论中添加图片 Aspose.Cells

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