Help on TXlsRange

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
marius
Posts: 12
Joined: Sat Jan 14, 2012 11:19 pm

Help on TXlsRange

Post by marius »

Hello Lars,

I'm trying to create a named range in an excel sheet but have no idea how to accomplish this in TXLSReadWriteII5.
The helpfile wont give me much decent answers (is there a searchable chm file, because html is limited in search?)
(The only thing i could find close to a range was a property Range: TXLSRange in the XLSSheetData5.TXLSWorksheet.html)

In FlexCel this is just two lines of code
DataRange := TXlsNamedRange.Create('LmsData', Export.ActiveSheet, 1, 1, 3, 25, 0, 0);
Export.SetNamedRange(DataRange);

How is this done in TXLSReadWriteII5 ?


Is there also a property or function i can use to search existing ranges (can lookup a predefined named range)?

Thanks,
Marius
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Help on TXlsRange

Post by larsa »

Hello

TXLSRange has nothing to do with defined names. It was used to format cell areas but is now obsoloete.
You add names with the Names object. Sample:

Code: Select all

  // function  Add(const AName,ADefinition: AxUCString): TXLSName; overload;
  // Add a name where the definition is an expression.
  // When creating names as expressions, its important that all cell/area
  // references are absolute. If not, the result is very unpredictable when
  // the name is used.
  XLS.Names.Add('Name3','Sheet1!$B$1');
  // Add another name as an expression.
  XLS.Names.Add('Name4','Sheet1!$B$1:$B$10');
  // The expression can be any valid formula.
  XLS.Names.Add('Name5','SUM(Sheet1!$B$1:$B$10)*100');
Find name:

Code: Select all

var
  S: AxUCString;
  Name: TXLSName;
begin
  // The name to search for.
  S := 'Name2';

  // Result is a TXLSName object.
  Name := XLS.Names.Find(S);
  // if not Nil, the name is found.
  if Name <> Nil then
    ShowMessage('Name "' + Name.Name + '" found. Definition: ' + Name.Definition)
  else
    ShowMessage('Name "' + S + '" not found.');
end;
Lars Arvidsson, Axolot Data
marius
Posts: 12
Joined: Sat Jan 14, 2012 11:19 pm

Re: Help on TXlsRange

Post by marius »

Hello Lars,

I was already afraid of it but was unable to find any other stuff (and obviously overlooked the property names).
Your helpfiles really lack a searchable format, and codesnippets etc etc ;)

But thank you Lars,
Marius
Post Reply