Hide or Show Excel Comments in C#

At some point, you may want to display or hide comments in an Excel document. This article shows you how to hide or show an existing comment in an excel document using Spire.XLS.

Detail steps:

Step 1: Instantiate a Workbook instance and load the excel document.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Comments.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Hide or show the specific comment in the worksheet.

//Hide comment
sheet.Comments[0].IsVisible = false;

//Show comment
//sheet.Comments[0].IsVisible = true;

Step 4: Save the document.

workbook.SaveToFile("HideComment.xlsx", ExcelVersion.Version2013);

Screenshot:

Hide or Show Excel Comments in C#

Full code:

//Instantiate a Workbook instance and load the excel document
Workbook workbook = new Workbook();
workbook.LoadFromFile("Comments.xlsx");

//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];

//Hide the specific comment in the worksheet
sheet.Comments[0].IsVisible = false;

//Show the specific comment in the worksheet
//sheet.Comments[0].IsVisible = true;

//Save the document
workbook.SaveToFile("HideComment.xlsx", ExcelVersion.Version2013);