Search Results for

    Show / Hide Table of Contents

    ExcelFile.Replace Method

    Overloads

    • ExcelFile.Replace(Object, Object, TXlsCellRange, Boolean, Boolean, Boolean)
    • ExcelFile.Replace(Object, Object, TXlsCellRange, Boolean, Boolean, Boolean, Action<TReplaceAction>)

    ExcelFile.Replace(Object, Object, TXlsCellRange, Boolean, Boolean, Boolean)

    Replaces the instances of oldValue by newValue in the active sheet.

    Syntax

    Namespace: FlexCel.Core

    public Int32 Replace(Object oldValue, Object newValue, TXlsCellRange Range, Boolean CaseInsensitive, Boolean SearchInFormulas, Boolean WholeCellContents)

    Parameters

    <-> Parameter Type Description
    oldValue Object Value we want to replace.
    newValue Object Value we want to use to replace oldValue.
    Range TXlsCellRange Range to Search. Null means the whole worksheet.
    CaseInsensitive Boolean If true, string searches will not be case sensitive, "a" = "A"
    SearchInFormulas Boolean If true, the search will cover formulas too.
    WholeCellContents Boolean If true, only whole cells will be replaced.

    Returns

    The number of replacements done.

    Examples

    To replace all cells on a sheet that contain "hello" with "hi":

        xls.Replace("hello", "hi", null, true, true, false);
    

    See also

    • ExcelFile

    ExcelFile.Replace(Object, Object, TXlsCellRange, Boolean, Boolean, Boolean, Action<TReplaceAction>)

    Replaces the instances of oldValue by newValue in the active sheet, and allows to specify the cell format and value for every replaced cell.

    Syntax

    Namespace: FlexCel.Core

    public abstract Int32 Replace(Object oldValue, Object newValue, TXlsCellRange Range, Boolean CaseInsensitive, Boolean SearchInFormulas, Boolean WholeCellContents, Action<TReplaceAction> ReplaceAction)

    Parameters

    <-> Parameter Type Description
    oldValue Object Value we want to replace.
    newValue Object Value we want to use to replace oldValue.
    Range TXlsCellRange Range to Search. Null means the whole worksheet.
    CaseInsensitive Boolean If true, string searches will not be case sensitive, "a" = "A"
    SearchInFormulas Boolean If true, the search will cover formulas too.
    WholeCellContents Boolean If true, only whole cells will be replaced.
    ReplaceAction Action<TReplaceAction> Action to be performed in every replacement.

    Returns

    The number of replacements done.

    Examples

    To replace all cells on a sheet that contain 1999-01-01 with 2003-01-01, formatting the cells in column 3 as blue:

        xls.Replace(new DateTime(1999, 01, 01), new DateTime(2003, 01, 01), null, true, true, true,
                    (x) =>
                      {
                          if (x.Col == 3)
                          {
                              TFlxFormat fm = x.Workbook.GetFormat(x.XF);
                              fm.FillPattern.FgColor = Colors.Red;
                              fm.FillPattern.Pattern = TFlxPatternStyle.Solid;
                              x.XF = x.Workbook.AddFormat(fm);
                          }
                      }
        );
    

    See also

    • ExcelFile
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com