News Category

Hide or Show Row Column Headers in Excel with C#

2017-09-05 08:33:06 Written by  support iceblue
Rate this item
(0 votes)

In Spire.XLS, we can hide or show the headers of rows and columns by setting the RowColumnHeadersVisible property of XlsWorksheet class. This article elaborates the steps of how to accomplish this function using Spire.XLS.

The following screenshot shows the input file which contain one worksheet with row and column headers.

Hide or Show Row Column Headers in Excel with C#

Detail steps:

Step 1: Instantiate a Workbook instance and load the Excel file.

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

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Hide or show the headers of rows and columns in the worksheet.

//Hide the headers of rows and columns
sheet.RowColumnHeadersVisible = false;

//Show the headers of rows and columns
//sheet.RowColumnHeadersVisible = true;

Step 4: Save the file.

workbook.SaveToFile("Output.xlsx");

The screenshot after hiding the row and column headers:

Hide or Show Row Column Headers in Excel with C#

Full code:

using Spire.Xls;
namespace ShowRowColumnHeader
{
    class Program
    {

        static void Main(string[] args)
        {
            // Instantiate a Workbook instance
            Workbook workbook = new Workbook();
            //Load the Excel file
            workbook.LoadFromFile("Input.xlsx");

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

            //Hide the headers of rows and columns
            sheet.RowColumnHeadersVisible = false;

            //Show the headers of rows and columns
            //sheet.RowColumnHeadersVisible = true;

            //Save the file
            workbook.SaveToFile("Output.xlsx");
        }
    }
}

Additional Info

  • tutorial_title:
Last modified on Friday, 12 April 2024 01:01