Hyperlinks[i].address does not return the correct value

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Hyperlinks[i].address does not return the correct value

Post by d3nton »

Hi!

It seems that the address property of hyperlinks does not return a correct value if I read an xls (Excel 97) file
which contains a hyperlink (XLSReadWrite 5.10.12).

Please see example: lString returns always 'file:///' .

var
ExcelFile5 : TXLSReadWriteII5;
lString: String;
begin
//creating file with hyperlink
ExcelFile5 := TXLSReadWriteII5.Create(nil);
ExcelFile5.Version := xvexcel97;
ExcelFile5.Filename := 'D:\output.xls';
ExcelFile5.Sheets[0].Name := 'test';

ExcelFile5[0].AsString[0,0] := 'C:\Windows\';
ExcelFile5[0].AsHyperlink[0,0] := 'C:\Windows\';
ExcelFile5.Write;
Sleep(100);
//now reading the file:
ExcelFile5.Read;
lString := ExcelFile5[0].hyperlinks[0].Address;
end.

d3nton
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Hyperlinks[i].address does not return the correct value

Post by d3nton »

Are there any news regarding this issue?
If you need further information to this bug, please let me know.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Hyperlinks[i].address does not return the correct value

Post by larsa »

Hello

Not sure where the error is. The problem is that hyperlinks are undocumented for Excel 97. Your code didn't work with version 4 either.
Lars Arvidsson, Axolot Data
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Hyperlinks[i].address does not return the correct value

Post by d3nton »

Hi!

Is there another solution for this? (unfortunately this is very important)
The main problem is in fact not the empty value of the Address property but another problem which is related to this, I think.
Adding a second sheet with hyperlinks to an
already existing xls file which already contains hyperlinks on a sheet, makes the hyperlinks of this first sheet dissappear.

var
ExcelFile5 : TXLSReadWriteII5;
lString: String;
begin
//creating file with hyperlink
ExcelFile5 := TXLSReadWriteII5.Create(nil);
ExcelFile5.Version := xvexcel97;
ExcelFile5.Filename := 'D:\output.xls';
ExcelFile5.Sheets[0].Name := 'test';

ExcelFile5[0].AsString[0,0] := 'C:\Windows\';
ExcelFile5[0].AsHyperlink[0,0] := 'C:\Windows\';
ExcelFile5.Write;
Sleep(100);
// the hyperlink works correct!
// now reading the file and adding a new sheet with a hyperlink:
ExcelFile5.Read;
ExcelFile5.Add;
ExcelFile5.Sheets[1].Name := 'test2';
ExcelFile5[1].AsString[0,0] := 'C:\Windows\';
ExcelFile5[1].AsHyperlink[0,0] := 'C:\Windows\';
ExcelFile5.Write;
End.
//If I open the file in Excel, the hyperlink on the first sheet (test1) does not work any longer.

Thank you and best regards.
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Hyperlinks[i].address does not return the correct value

Post by d3nton »

Hi.

Is there any news on this?
Maybe a workaround to keep old hyperlinks of a xls file when adding a new sheet to the file?

Thanks in advance.

Best regards.
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Hyperlinks[i].address does not return the correct value

Post by d3nton »

I tried to fix this on my own but only with limited success.
My problem is, that I want to read a file with hyperlinks and add a new sheet in it.
I do not really want to read the existing hyperlinks (i do not need the hyperlink addresses) but when reading the file, old hyperlinks will be destroyed, because they are read automatically.
It seems that procedure TXLSReadII.RREC_HLINK;
tries to add new hyperlinks (line: 1842: HLink := TXLSHyperlink(FCurrXc12Sheet.Hyperlinks.Add);
but the hyperlink address is not set successfully.
If I disable this procedure. I can read a xls file with hyperlinks and add a new sheet to it, without destroying the old hyperlinks.
(I removed line 662 in BIFF_ReadII5.pas : BIFFRECID_HLINK : RREC_HLINK; which fixes the issue).
Unfortunately I have to add the fix manually, each time I update XLSReadWrite.
If you cannot find the exact error (seem to be some pointer problems in TXLSReadII.RREC_HLINK) it would be nice if you could e.g. add an optional parameter e.g. to TXLSReadWriteII5.Read;
-> TXLSReadWriteII5.Read(pReadHyperlinks : Boolean = true). If set to false, the existing hyperlinks will not be read.
What do you think of that?
Or maybe you find another solution?
Thank you very much for all your help.

Best regards
Arno
Post Reply