Hide or Unhide Excel Row and Column in WPF

Sometimes, hide row and column can make the data processing job easier and more efficient when working with a large excel file. However, hidden rows and columns are always hidden and invisible, for this reason, you need to unhide them before showing the whole excel file.

Spire.XLS for WPF provides developers four methods: HideRow(), HideColumn(), ShowRow() and ShowColumn() to hide or unhide excel row and column in WPF.

Please check the screenshot of the original excel worksheet:

Hide or Unhide Excel Row and Column in WPF

Before using the code, make sure that Spire.XLS is installed on system correctly, next create a WPF application project and add the dll file from the installation folder as reference, after that use following namespace:

using System.Windows;
using Spire.Xls;

Code snippets:

Step 1: Initialize a new instance of Workbook class and load the original excel file.

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

Step 2: Get the first worksheet of the file.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Hide or unhide row and column.

Hide the 8th row and the 3rd column:

sheet.HideRow(8);
sheet.HideColumn(3);

Unhide:

sheet.ShowRow(8);
sheet.ShowColumn(3);

Step 4: Save and launch the file.

Effective screenshot after hiding:

Hide or Unhide Excel Row and Column in WPF

Full codes:

using Spire.Xls;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //initialize a new instance
            Workbook workbook = new Workbook();
            //load the sample excel file
            workbook.LoadFromFile("Excel.xlsx");
            //get its first worksheet 
            Worksheet sheet = workbook.Worksheets[0];

            //hide the 8th row and the 3rd column of the first worksheet
            sheet.HideRow(8);
            sheet.HideColumn(3);
            /*//unhide
            sheet.ShowRow(8);           
            sheet.ShowColumn(3);*/

            //save and launch the file
            workbook.SaveToFile("Sample.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start(workbook.FileName);
        }

    }
}