function TXLSNames.Add bug

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
Moisha
Posts: 18
Joined: Wed Apr 06, 2016 1:00 pm

function TXLSNames.Add bug

Post by Moisha »

hi.
Here is function text

Code: Select all

function TXLSNames.Add(const AName, ASheetName: AxUCString; const ACol, ARow: integer): TXLSName;
var
  Def: AxUCString;
begin
  if FManager.Worksheets.Find(ASheetName) < 0 then begin
    FManager.Errors.Error(ASheetName,XLSERR_FMLA_UNKNOWNSHEET);
    Result := Nil;
  end
  else begin
    Def := ASheetName+ '!' + ColRowToRefStr(ACol,ARow,True,True);
    Result := Add(AName,Def);
  end;
end;
Problem occurs if ASheetName has special symbol i.e. "one-two"
Tokenizer breaks sheet name on this symbol and can not find sheet with name "one".
Quoting sheet name is not an option because

Code: Select all

FManager.Worksheets.Find(ASheetName)
does not check quotes and can not find sheet with quoted name.

i suggest to fix function in this way:

Code: Select all

Def := QuotedStr(ASheetName)+ '!' + ColRowToRefStr(ACol,ARow,True,True);
regards
Anton
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: function TXLSNames.Add bug

Post by larsa »

Hello

Sheet names with special characters in Names and formulas shall be quoted with single quotes.

Regarding the rest, please give me a code sample on what is not working.
Lars Arvidsson, Axolot Data
Moisha
Posts: 18
Joined: Wed Apr 06, 2016 1:00 pm

Re: function TXLSNames.Add bug

Post by Moisha »

Here is code generating described error.

Code: Select all

program AddNameErr;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  XLSSheetData5,
  XLSReadWriteII5;

var xls: TXLSReadWriteII5;
    sheet: TXLSWorksheet;

begin
  xls := TXLSReadWriteII5.Create(nil);
  sheet := xls.Add();
  sheet.Name := 'one two';
  try
    xls.Names.Add('name1', sheet.name, 1, 1);
  except
    // Project AddNameErr.exe raised exception class Exception with message 'E4016: Uknown sheet name "two"'.
  end;

  try
    xls.Names.Add('name1', QuotedStr(sheet.name), 1, 1);
  except
    // quoting does not help
    // Project AddNameErr.exe raised exception class Exception with message 'E4016: Uknown sheet name "'one two'"'.
  end;
end.
Suggested corrections fix it and user has no need to quote sheet name.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: function TXLSNames.Add bug

Post by larsa »

Hello

The code works fine here. Tested wit version 6.00.07
Lars Arvidsson, Axolot Data
Moisha
Posts: 18
Joined: Wed Apr 06, 2016 1:00 pm

Re: function TXLSNames.Add bug

Post by Moisha »

Hi.

Code fails on last XLSReadWriteII 5 for XE4 from http://www.axolot.com/components/f_downloadreg.htm.
Is version 5 supported or it is nessessary to buy version 6 for further support?

Regards.
Anton.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: function TXLSNames.Add bug

Post by larsa »

Hello

Sorry, but we only supports the latest version (now version 6).
Lars Arvidsson, Axolot Data
Post Reply