TExcelFile.SetNamedRange Method
Overloads
TExcelFile.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.Core
function TExcelFile.SetNamedRange(const rangeData: TXlsNamedRange): Integer; overload; virtual; abstract;
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
TExcelFile.SetNamedRange(Integer, 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
Unit: FlexCel.Core
procedure TExcelFile.SetNamedRange(const index: Integer; const rangeData: TXlsNamedRange); overload; virtual; abstract;
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.