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

Worksheet.GetExistingCells() Method

Gets the existing cells in the worksheet.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

IEnumerable<Cell> GetExistingCells()

#Returns

Type Description
IEnumerable<Cell>

An enumerator that supports iteration over the cell collection.

#Remarks

Use the GetExistingCells method to iterate through the collection of existing cells in the worksheet. The GetExistingCells collection includes the following cells:

  • Cells that contain a CellRange.Value or CellRange.Formula;
  • Cells that have any Formatting properties which are not null;
  • Top-left cells of merged cells;
  • Cells that contained a value or had cell formatting options applied at any time. For example, if the cell A1 contained a value that was later deleted, the cell A1 is included in the GetExistingCells collection.

#Example

The following code snippet iterates through existing cells to remove the name prefix of the user-defined function (UDF) of the Excel XLL Add-in. You can implement your own user-defined function instead.

IEnumerable<DevExpress.Spreadsheet.Cell> existingCells = spreadsheetControl1.ActiveWorksheet.GetExistingCells();
spreadsheetControl1.Document.BeginUpdate();
foreach (DevExpress.Spreadsheet.Cell cell in existingCells)
{
    if (cell.HasFormula)
        // The worksheet references functions from the DiscountXLL.MyFunctions xll Add-in. 
        // The name prefix is removed leaving only the function name.
        cell.Formula = cell.Formula.Replace("_xll.DiscountXLL.MyFunctions.", string.Empty);
}
spreadsheetControl1.Document.EndUpdate();
See Also