From 75fea056850cb55edb66aaaa38dc1a1aa38d71cf Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 14 Oct 2014 08:29:28 +0000 Subject: [PATCH] fpspreadsheet: Fix issue 0025133 "Cannot read xls file apparently BIFF5". Fix error message when writing a too-long cell text to BIFF5. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3653 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/tests/spreadtestgui.lpi | 1 + .../fpspreadsheet/uvirtuallayer_ole.pas | 42 ++++++++++++------- components/fpspreadsheet/xlsbiff5.pas | 2 +- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/components/fpspreadsheet/tests/spreadtestgui.lpi b/components/fpspreadsheet/tests/spreadtestgui.lpi index 8b11c02d0..4dfdcacc7 100644 --- a/components/fpspreadsheet/tests/spreadtestgui.lpi +++ b/components/fpspreadsheet/tests/spreadtestgui.lpi @@ -109,6 +109,7 @@ + diff --git a/components/fpspreadsheet/uvirtuallayer_ole.pas b/components/fpspreadsheet/uvirtuallayer_ole.pas index 07351a162..bbaf6162f 100644 --- a/components/fpspreadsheet/uvirtuallayer_ole.pas +++ b/components/fpspreadsheet/uvirtuallayer_ole.pas @@ -228,21 +228,28 @@ var Splitted: TStringList; j: integer; SIDChild: SID; + function FindSiblingWithName(const AName: WideString; const AStartSibling: integer): SID; + var + n, ab: WideString; begin - if (FDirectory[AStartSibling]._ab=AName) and (FDirectory[AStartSibling]._mse<>BYTE(STGTY_INVALID)) then begin + n := UpperCase(AName); + ab := UpperCase(FDirectory[AStartSibling]._ab); + if (n = ab) and (FDirectory[AStartSibling]._mse <> BYTE(STGTY_INVALID)) then + begin Result:=FDirectory[AStartSibling]._sidChild; - end else begin + end else + begin Result:=WINCOMPOUND_NOSID; - if FDirectory[AStartSibling]._sidLeftSib<>WINCOMPOUND_NOSID then begin + if FDirectory[AStartSibling]._sidLeftSib<>WINCOMPOUND_NOSID then Result:=FindSiblingWithName(AName,FDirectory[AStartSibling]._sidLeftSib); - end; - if Result<>WINCOMPOUND_NOSID then exit; - if FDirectory[AStartSibling]._sidRightSib<>WINCOMPOUND_NOSID then begin + if Result<>WINCOMPOUND_NOSID then + exit; + if FDirectory[AStartSibling]._sidRightSib<>WINCOMPOUND_NOSID then Result:=FindSiblingWithName(AName,FDirectory[AStartSibling]._sidRightSib); - end; end; end; + begin Splitted:=TStringList.Create; SplitPath(APath,Splitted); @@ -265,21 +272,26 @@ var Splitted: TStringList; j: integer; SIDChild: SID; + function FindSiblingWithName(const AName: WideString; const AStartSibling: integer): SID; + var + n, ab: WideString; begin - if (FDirectory[AStartSibling]._ab=AName) and (FDirectory[AStartSibling]._mse<>BYTE(STGTY_INVALID)) then begin - Result:=AStartSibling; - end else begin + n := UpperCase(AName); + ab := UpperCase(FDirectory[AStartSibling]._ab); + if (n = ab) and (FDirectory[AStartSibling]._mse <> BYTE(STGTY_INVALID)) then + Result := AStartSibling + else begin Result:=WINCOMPOUND_NOSID; - if FDirectory[AStartSibling]._sidLeftSib<>WINCOMPOUND_NOSID then begin + if FDirectory[AStartSibling]._sidLeftSib<>WINCOMPOUND_NOSID then Result:=FindSiblingWithName(AName,FDirectory[AStartSibling]._sidLeftSib); - end; - if Result<>WINCOMPOUND_NOSID then exit; - if FDirectory[AStartSibling]._sidRightSib<>WINCOMPOUND_NOSID then begin + if Result<>WINCOMPOUND_NOSID then + exit; + if FDirectory[AStartSibling]._sidRightSib<>WINCOMPOUND_NOSID then Result:=FindSiblingWithName(AName,FDirectory[AStartSibling]._sidRightSib); - end; end; end; + begin Splitted:=TStringList.Create; SplitPath(APath,Splitted); diff --git a/components/fpspreadsheet/xlsbiff5.pas b/components/fpspreadsheet/xlsbiff5.pas index f5bd3deb6..5d549da23 100755 --- a/components/fpspreadsheet/xlsbiff5.pas +++ b/components/fpspreadsheet/xlsbiff5.pas @@ -785,7 +785,7 @@ begin // Rather than lose data when reading it, let the application programmer deal // with the problem or purposefully ignore it. AnsiValue := Copy(AnsiValue, 1, MAXBYTES); - Workbook.AddErrorMsg(rsInvalidCharacterInCell, [ + Workbook.AddErrorMsg(rsTruncateTooLongCellText, [ MAXBYTES, GetCellString(ARow, ACol) ]); end;