Table of Contents

TXlsFile.SetNamedRange Method

Overloads

TXlsFile.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 TInternalNameRange Look at the example for more information.

Syntax

Unit: FlexCel.XlsAdapter

function TXlsFile.SetNamedRange(const rangeData: TXlsNamedRange): Integer; overload; override;

Parameters

<-> Parameter Type Description
const 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(TXlsNamedRange.Create(TXlsNamedRange.GetInternalName(TInternalNameRange.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

TXlsFile.SetNamedRange(Integer, TXlsNamedRange)

Modifies a Named Range in the specified position. You could normally use TExcelFile.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. TExcelFile.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

Unit: FlexCel.XlsAdapter

procedure TXlsFile.SetNamedRange(const index: Integer; const rangeData: TXlsNamedRange); overload; override;

Parameters

<-> Parameter Type Description
const index Integer Index of the named range we are trying to modify.
const 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":

var
  printArea: TXlsNamedRange;
  nameIndex: Int32;
  range: TXlsNamedRange;
...
  nameIndex := xls.FindNamedRange('MyName', -1);  //Find the name index from the name.
  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