How to Set Picture Fill for Excel Comment in C#, VB.NET

Spire.XLS enable programmers to insert, modify as well as format comments in Excel. Also, it allows users to fill a comment with solid color, gradient, pattern or a picture to change the look of the comment. This article is going to introduce how to set background image for a comment in Excel using Spire.XLS.

Code Snippet:

Step 1: Initialize an instance of Wordbook and get the first worksheet.

Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];

Step 2: Fill the comment with a customized background picture.

Image image = Image.FromFile(@"C: \Users\Administrator\Desktop\logo.png");
sheet.Range["C6"].Comment.Fill.CustomPicture(image, "logo.png");

Step 3: Re-set the size of comment box.

sheet.Range["C6"].Comment.Height = image.Height;
sheet.Range["C6"].Comment.Width = image.Width;

Step 4: Save the file.

wb.SaveToFile("PicFillComment.xls", ExcelVersion.Version97to2003);

Output:

How to Set Picture Fill for Excel Comment in C#, VB.NET

Full Code:

[C#]
using Spire.Xls;
using System.Drawing;
namespace SetPictureFill
{
    class Program
    {

        static void Main(string[] args)
        {
            {

                Workbook wb = new Workbook();
                Worksheet sheet = wb.Worksheets[0];

                Image image = Image.FromFile(@"C: \Users\Administrator\Desktop\logo.png");
                sheet.Range["C6"].Comment.Fill.CustomPicture(image, "logo.png");
                sheet.Range["C6"].Comment.Height = image.Height;
                sheet.Range["C6"].Comment.Width = image.Width;

                wb.SaveToFile("PicFill.xls", ExcelVersion.Version97to2003);

            }

        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports System.Drawing
Namespace SetPictureFill
	Class Program

		Private Shared Sub Main(args As String())
			If True Then

				Dim wb As New Workbook()
				Dim sheet As Worksheet = wb.Worksheets(0)

				Dim image__1 As Image = Image.FromFile("C: \Users\Administrator\Desktop\logo.png")
				sheet.Range("C6").Comment.Fill.CustomPicture(image__1, "logo.png")
				sheet.Range("C6").Comment.Height = image__1.Height
				sheet.Range("C6").Comment.Width = image__1.Width

				wb.SaveToFile("PicFill.xls", ExcelVersion.Version97to2003)

			End If

		End Sub
	End Class
End Namespace