C#/VB.NET: Hide or Show Comments in Excel

2023-06-28 06:43:00 Written by  support iceblue
Rate this item
(0 votes)

Comments in Excel are blocks of text that can be added to cells, mainly used to provide additional explanation or supplemental information about the cell contents. Users can add comments to the specific cells to better explain the data of worksheets. However, sometimes too many comments will cause visual clutter or obstruct other content. To avoid this issue, existing comments can be hidden programmatically to make the worksheet more organized and readable. Hidden comments can also be easily displayed when necessary. In this article, you will learn how to hide or show comments in excel by using Spire.XLS for .NET.

Install Spire.XLS for .NET

To begin with, you need to add the DLL files included in the Spire.XLS for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.XLS

Hide Comments in Excel

Spire.XLS for .NET provides the Worksheet.Comments[].IsVisble property to control the visibility of comments. You can easily hide existing comments by setting this property to "false". The following are the detailed steps to hide comments in excel.

  • Initialize a Workbook instance.
  • Load a sample file using Workbook.LoadFromFile() method.
  • Get the desired worksheet through Workbook.Worksheets[] property.
  • Hide the specific comment in the worksheet by setting Worksheet.Comments[].IsVisble property to "false".
  • Finally, save the result file using Workbook.SavaToFile() method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ShowExcelComments
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                //Initialize 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;

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

C#/VB.NET: Hide or Show Comments in Excel

Show Comments in Excel

Hidden comments can also be easily displayed when necessary. If you want to show it again, please set Worksheet.Comments[].IsVisble property to "ture". The following are the steps to show comments in excel.

  • Initialize a Workbook instance.
  • Load a sample file using Workbook.LoadFromFile() method.
  • Get the desired worksheet through Workbook.Worksheets[] property.
  • Show the specific comment in the worksheet By setting Worksheet.Comments[].IsVisble property to "true".
  • Finally, save the result file using Workbook.SavaToFile() method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ShowExcelComments
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                //Initialize a Workbook instance and load the excel document
                Workbook workbook = new Workbook();
                workbook.LoadFromFile("HideComment.xlsx");

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

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

                //Save the document
                workbook.SaveToFile("ShowComment.xlsx", ExcelVersion.Version2013);
                workbook.Dispose();
            }
        }
    }
}

C#/VB.NET: Hide or Show Comments in Excel

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Wednesday, 28 June 2023 00:55