Aspose.Cells实现添加图片到单元格注释里
Aspose.Cells是一款功能强大的Excel电子数据表格控件,不需要电脑安装Excel的情况下实现对Excel文件的各种操作,下面我们介绍了如何使用该产品通过代码为单元格添加图片注释。
[C#]
//Instantiate a Workbook
Workbook workbook = new Workbook();
//Get a reference of comments collection with the first sheet
CommentCollection comments = workbook.Worksheets[0].Comments;
//Add a comment to cell A1
int commentIndex = comments.Add(0, 0);
Comment comment = comments[commentIndex];
comment.Note = "First note.";
comment.Font.Name = "Times New Roman";
//Load an image into stream
Bitmap bmp = new Bitmap("e:\\test\\school.jpg");
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//Set image data to the shape associated with the comment
comment.CommentShape.FillFormat.ImageData = ms.ToArray();
//Save the workbook
workbook.Save(@"e:\test2\commentwithpicture1.xlsx", Aspose.Cells.SaveFormat.Xlsx);
[VB]
'Instantiate a Workbook
Dim workbook As New Workbook()
'Get a reference of comments collection with the first sheet
Dim comments As CommentCollection = workbook.Worksheets(0).Comments
'Add a comment to cell A1
Dim commentIndex As Integer = comments.Add(0, 0)
Dim comment As Comment = comments(commentIndex)
comment.Note = "First note."
comment.Font.Name = "Times New Roman"
'Load an image into stream
Dim bmp As New Bitmap("e:\test\school.jpg")
Dim ms As New MemoryStream()
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
'Set image data to the shape associated with the comment
comment.CommentShape.FillFormat.ImageData = ms.ToArray()
'Save the workbook
workbook.Save("e:\test2\commentwithpicture1.xlsx", Aspose.Cells.SaveFormat.Xlsx)