fpspreadsheet: Fix handling of hyperlinks with spaces in the bookmark (sheet name).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8604 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-11-10 19:23:23 +00:00
parent d2467e166d
commit eb0d7767fb
2 changed files with 23 additions and 2 deletions

View File

@ -162,6 +162,25 @@ procedure TsWorksheet.WriteHyperlink(ACell: PCell; ATarget: String;
Result := ATarget;
end;
function CheckTarget(ATarget: String): String;
var
p1, p2: Integer;
sheetName: String;
begin
Result := ATarget;
p1 := pos('#', ATarget);
p2 := pos('!', ATarget);
if (p1 > 0) and (p2 > p1) then
begin
sheetName := copy(ATarget, p1+1, p2-p1-1);
if (sheetName <> '') and (pos(' ', sheetName) > 0) and (sheetName[1] <> '''') then
begin
sheetName := '''' + sheetName + '''';
Result := copy(ATarget, 1, p1) + sheetName + copy(ATarget, p2, MaxInt);
end;
end;
end;
var
fmt: TsCellFormat;
noCellText: Boolean = false;
@ -186,7 +205,7 @@ begin
(GetDisplayText(ReadHyperlink(ACell).Target) = ReadAsText(ACell));
// Attach the hyperlink to the cell
FHyperlinks.AddHyperlink(ACell^.Row, ACell^.Col, ATarget, ATooltip);
FHyperlinks.AddHyperlink(ACell^.Row, ACell^.Col, CheckTarget(ATarget), ATooltip);
Include(ACell^.Flags, cfHyperlink);
// If there is no other cell content use the target as cell label string.

View File

@ -960,7 +960,9 @@ begin
Result := ParseCellString(AStr, ACellRow, ACellCol);
ASheetName := '';
end else begin
ASheetName := UTF8Copy(AStr, 1, p-1);
ASheetName := Copy(AStr, 1, p-1);
if (ASheetName[1] = '''') and (ASheetName[Length(ASheetName)] = '''') then
ASheetName := Copy(ASheetName, 2, Length(ASheetName)-2);
Result := ParseCellString(Copy(AStr, p+1, Length(AStr)), ACellRow, ACellCol);
end;
end;