向Excel备注添加图片
Contents
[
Hide
]
Microsoft Excel允许用户在很大程度上自定义电子表格的外观和感觉。甚至可以向备注添加背景图片。
备注被添加到单元格中以记录评论,可以是关于公式运算细节、数值来源或审核者的问题等任何内容。添加背景图片可以是一种美学选择,也可以用于加强品牌。
使用Microsoft Excel向Excel备注中添加图片
在Microsoft Excel 2007中,可以将图像作为单元格备注的背景。在Excel 2007中,可以这样完成(假设已经添加了备注):
- 右键单击包含评论的单元格。
- 选择显示/隐藏评论并清除评论中的任何文本。 1.选择格式,然后选择注释。
- 选择格式,然后选择评论。
- 在“颜色和线条”选项卡上,单击“颜色”的箭头。 1.单击图片选项卡。
- 在“图片”选项卡上,单击选择图片。
- 定位并选择图片
- 点击确定。
向Excel评论中添加图片 Aspose.Cells
Aspose.Cells提供了这一宝贵的功能。
下面的示例代码从头创建一个XLSX文件,并向单元格A1添加带图片背景的评论。
执行代码后,A1将带有背景图片的评论。
输出文件
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |