将图片添加到 Excel 注释
Contents
[
Hide
]
Microsoft Excel 允许用户在很大程度上自定义电子表格的外观。甚至可以在评论中添加背景图片。
将注释添加到单元格以记录注释、公式工作方式的详细信息、值的来源或审阅者的问题等任何内容。添加背景图像可以是一种审美选择,也可以用于强化品牌。
用 Microsoft Excel 添加图片到 Excel 注释
使用 Microsoft Excel 2007,可以将图像作为单元格注释的背景。在 Excel 2007 中,这是通过以下方式完成的(假设已经添加了注释):
- 右键单击包含注释的单元格。
- 选择显示/隐藏评论并清除评论中的任何文本。
- 单击评论的边框以将其选中。
- 选择格式, 然后评论.
- 在颜色和线条选项卡上,单击箭头颜色.
- 点击填充效果.
- 在图片选项卡上,单击选择图片.
- 找到并选择图片
- 点击好的.
用 Aspose.Cells 将图片添加到 Excel 注释
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"); |