Remove conditional format from Excel in C#

2017-09-07 03:17:47 Written by  support iceblue
Rate this item
(0 votes)

With the help of Spire.XLS, we can set the conditional format the Excel cell in C# and VB.NET. We can also use Spire.XLS to remove the conditional format from a specific cell or the entire Excel worksheet. This article will demonstrate how to remove conditional format from Excel in C#.

Firstly, view the original Excel worksheet with conditional formats:

Remove conditional format from Excel in C#

Step 1: Create an instance of Excel workbook and load the document from file.

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

Step 2: Get the first worksheet from the workbook.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Remove the conditional formats from the specific Excel Cell B2.

sheet.Range["B2"].ConditionalFormats.Remove();

Step 4: Remove all the conditional formats from the whole Excel worksheet.

sheet.AllocatedRange.ConditionalFormats.Remove();

Step 5: Save the document to file.

workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);

Remove the conditional format from a special Excel range B2:

Remove conditional format from Excel in C#

Remove all the conditional formats from the entire Excel worksheet:

Remove conditional format from Excel in C#

Full codes of how to remove the conditional formats from Excel worksheet:

using Spire.Xls;
namespace RemoveConditionalFormat
{
    class Program
    {
        static void Main(string[] args)
        {
            {

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

                Worksheet sheet = workbook.Worksheets[0];

                //sheet.Range["B2"].ConditionalFormats.Remove();

                sheet.AllocatedRange.ConditionalFormats.Remove();

                workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
            }

        }
    }
}

Additional Info

  • tutorial_title:
Last modified on Monday, 06 September 2021 02:34