Using named ranges

1 I need to be able to show list of the named ranges to the user
2. User selects named range
3. Than we add data to the end of the named range and named range automatically expands

How can we do it?

VC



Hi,

To display a list of named ranges you can do something like:
var
  i: integer;
  name: TXlsNamedRange;
begin
for i := 1 to xls.NamedRangeCount do
begin
  name := Xls.GetNamedRange(i);
  SomeListbox.Add(name.Name); //you could filter by some condition in the name.
end;
end;

After the user selects a name, you can use Name.FirstRow, Name.LastRow, Name.FirstCol and Name.LastCol to learn the coordinates of the name. (that is always that the name has coordinates, it could be a formula like "= 2 + 3" and in this cases the values of firstrow, etc will be negative)

Once you know the coordinates, you might insert rows or cells with xls.InsertAndCopyRange(...) to make the range autoexpand, and then use xls.SetCellValue(...) to fill the cells.
Or if you prefer not to insert ranges, you can always modify the name and call xls.SetNamedRange(...) to get the expanded name.