Skip to main content
Row

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ColumnCollection.Remove(Int32, Int32, Func<Int32, Boolean>) Method

Removes columns that match the specified condition from the worksheet.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

void Remove(
    int first,
    int last,
    Func<int, bool> predicate
)

#Parameters

Name Type Description
first Int32

An integer that specifies the index of a column from which the check should start.

last Int32

An integer that specifies the index of a column on which the check should end.

predicate Func<Int32, Boolean>

A delegate that is the function to check for a condition in each column.

#Example

View Example

workbook.LoadDocument("Documents\\Document.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Create a function specifying the condition to remove worksheet columns.
Func<int, bool> columnRemovalCondition = x => worksheet.Cells[0, x].Value.NumericValue > 3.0 && worksheet.Cells[0, x].Value.NumericValue < 14.0;

// Fill cells with data.
for (int i = 0; i < 15; i++)
{
    worksheet.Cells[i, 0].Value = i + 1;
    worksheet.Cells[0, i].Value = i + 1;
}

// Delete all columns that meet the specified condition.
//worksheet.Columns.Remove(columnRemovalCondition);

// Delete columns that meet the specified condition starting from the 7th column.
worksheet.Columns.Remove(7, columnRemovalCondition);

// Delete columns that meet the specified condition starting from the 5th column to the 14th column.
//worksheet.Columns.Remove(5, 14, columnRemovalCondition);
See Also