FormatConditionCollection.RemoveArea

RemoveArea(int)

Removes conditional formatted cell range by index.

public void RemoveArea(int index)
ParameterTypeDescription
indexInt32The index of the conditional formatted cell range to be removed.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class FormatConditionCollectionMethodRemoveAreaWithInt32Demo
    {
        public static void Run()
        {
            // Create a workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Add conditional formatting
            ConditionalFormattingCollection conditionalFormattings = worksheet.ConditionalFormattings;
            int index = conditionalFormattings.Add();
            FormatConditionCollection formatConditionCollection = conditionalFormattings[index];

            // Add areas to format
            formatConditionCollection.AddArea(CellArea.CreateCellArea(0, 0, 10, 5)); // First area
            formatConditionCollection.AddArea(CellArea.CreateCellArea(5, 5, 15, 10)); // Second area

            // Add a condition
            formatConditionCollection.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "10", "100");

            // Display initial area count (we know we added 2 areas)
            Console.WriteLine("Areas before removal: 2");

            // Remove the second area (index 1)
            formatConditionCollection.RemoveArea(1);

            // Display area count after removal (we know we removed 1 area)
            Console.WriteLine("Areas after removal: 1");

            // Save the workbook
            workbook.Save("RemoveAreaDemo.xlsx");
        }
    }
}

See Also


RemoveArea(int, int, int, int)

Remove conditional formatting int the range.

public bool RemoveArea(int startRow, int startColumn, int totalRows, int totalColumns)
ParameterTypeDescription
startRowInt32The startRow of the range.
startColumnInt32The startColumn of the range.
totalRowsInt32The number of rows of the range.
totalColumnsInt32The number of columns of the range.

Return Value

Returns TRUE, this FormatCondtionCollection should be removed.

Examples

using System;
using Aspose.Cells;
using System.Drawing;

namespace AsposeCellsExamples
{
    public class FormatConditionCollectionMethodRemoveAreaWithInt32Int32Int32Int32Demo
    {
        public static void Run()
        {
            Workbook wb = new Workbook();
            Worksheet sheet = wb.Worksheets[0];
            ConditionalFormattingCollection cfc = sheet.ConditionalFormattings;
            
            int idx = cfc.Add();
            FormatConditionCollection fcc = cfc[idx];
            
            // Add initial area
            CellArea initialArea = CellArea.CreateCellArea(0, 0, 0, 0);
            fcc.AddArea(initialArea);
            
            // Add condition
            idx = fcc.AddCondition(FormatConditionType.Expression);
            FormatCondition fc = fcc[idx];
            fc.Formula1 = "=A1>0";
            fc.Style.Font.Color = Color.Red;
            
            // Demonstrate RemoveArea with Int32 parameters
            Console.WriteLine("Before removal - Areas count: " + fcc.Count);
            fcc.RemoveArea(0, 0, 1, 1); // Remove the initial area
            Console.WriteLine("After removal - Areas count: " + fcc.Count);
            
            // Add new area
            CellArea newArea = CellArea.CreateCellArea(1, 1, 1, 1);
            fcc.AddArea(newArea);
            Console.WriteLine("After adding new area - Areas count: " + fcc.Count);
        }
    }
}

See Also