Search Results for

    Show / Hide Table of Contents

    ExcelFile.SetNamedRange Method

    Overloads

    • ExcelFile.SetNamedRange(TXlsNamedRange)
    • ExcelFile.SetNamedRange(Int32, TXlsNamedRange)

    ExcelFile.SetNamedRange(TXlsNamedRange)

    Modifies or adds a Named Range. If the named range exists, it will be modified, else it will be added. If the range is not user defined (like "Print_Area") it will have a one-char name, and the value is on the enum InternalNameRange Look at the example for more information.

    Syntax

    Namespace: FlexCel.Core

    public abstract Int32 SetNamedRange(TXlsNamedRange rangeData)

    Parameters

    <-> Parameter Type Description
    rangeData TXlsNamedRange Data of the named range. You don't need to specify the RPN Array.

    Returns

    The name index of the inserted or modified range (1 based).

    Examples

    This will create a range for repeating the first 2 columns and rows on each printed page (on sheet 1):

        xls.SetNamedRange(new TXlsNamedRange(TXlsNamedRange.GetInternalName(InternalNameRange.Print_Titles), SheetIndex, 0, "=1:2,A:B"));
    

    Note that in this example in particular (Print_Titles), the range has to have full rows/columns, as this is what Excel expects. You should also use "A:B" notation instead of the full "A1:B65536" name, so it will work in Excel 2007 too.

    See also

    • ExcelFile

    ExcelFile.SetNamedRange(Int32, TXlsNamedRange)

    Modifies a Named Range in the specified position. You could normally use SetNamedRange(TXlsNamedRange) to do this, but if you want to modify the name of the named range, then you need to use this overloaded version. SetNamedRange(TXlsNamedRange) would add a new range instead of modifying the existing one if you change the name. Look at the example for more information on how to use it.

    Syntax

    Namespace: FlexCel.Core

    public abstract void SetNamedRange(Int32 index, TXlsNamedRange rangeData)

    Parameters

    <-> Parameter Type Description
    index Int32 Index of the named range we are trying to modify.
    rangeData TXlsNamedRange Data of the named range. You don't need to specify the RPN Array.

    Examples

    This will modify the name of the named range "MyName":

        int nameIndex = xls.FindNamedRange("MyName", -1);  //Find the name index from the name.
        TXlsNamedRange range = xls.GetNamedRange(nameIndex); //Load the name definition for the name index.
        range.Name = "MyNewName";  //Modify the name definition.
        xls.SetNamedRange(nameIndex, range);  //Set the new name definition into the file.
    

    See also

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