fpspreadsheet: Add error log entry when reading xlsx files with non-numeric data in numeric cells, instead of aborting the program. Issue #37055, modified patch by Tulurdes.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7452 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-05-13 05:42:33 +00:00
parent 085e3db4fe
commit 92a0c02e8f

View File

@ -736,6 +736,7 @@ begin
tnode := tnode.NextSibling; tnode := tnode.NextSibling;
end; end;
end; end;
if (boReadFormulas in book.Options) and ((nodeName = 'f') or (nodeName = 'x:f'))then if (boReadFormulas in book.Options) and ((nodeName = 'f') or (nodeName = 'x:f'))then
begin begin
// Formula to cell // Formula to cell
@ -800,7 +801,8 @@ begin
else else
if (s = '') or (s = 'n') then begin if (s = '') or (s = 'n') then begin
// Number or date/time, depending on format // Number or date/time, depending on format
number := StrToFloat(dataStr, FPointSeparatorSettings); if TryStrToFloat(dataStr, number, FPointSeparatorSettings) then
begin
if IsDateTimeFormat(numFmt) then if IsDateTimeFormat(numFmt) then
begin begin
if not IsTimeIntervalFormat(numFmt) then // no correction of time origin for "time interval" format if not IsTimeIntervalFormat(numFmt) then // no correction of time origin for "time interval" format
@ -811,11 +813,17 @@ begin
sheet.WriteText(cell, dataStr) sheet.WriteText(cell, dataStr)
else else
sheet.WriteNumber(cell, number); sheet.WriteNumber(cell, number);
end else
workbook.AddErrorMsg(
'Error reading cell %s: Failure to convert "%s" to number.', [
GetCellString(rowindex, colindex), dataStr
]);
end end
else else
if s = 's' then begin if s = 's' then begin
// String from shared strings table // String from shared strings table
sstIndex := StrToInt(dataStr); if TryStrToInt(dataStr, sstIndex) then
begin
sheet.WriteText(cell, FSharedStrings[sstIndex]); sheet.WriteText(cell, FSharedStrings[sstIndex]);
// Read rich-text parameters from the stream stored in the Objects of the stringlist // Read rich-text parameters from the stream stored in the Objects of the stringlist
if FSharedStrings.Objects[sstIndex] <> nil then if FSharedStrings.Objects[sstIndex] <> nil then
@ -826,6 +834,11 @@ begin
SetLength(cell^.RichTextParams, n); SetLength(cell^.RichTextParams, n);
ms.ReadBuffer(cell^.RichTextParams[0], n*SizeOf(TsRichTextParam)); ms.ReadBuffer(cell^.RichTextParams[0], n*SizeOf(TsRichTextParam));
end; end;
end else
workbook.AddErrorMsg(
'Error readind cell %s: Failure to extract SST index from value "%s"', [
GetCellString(rowindex, colindex), dataStr
]);
end else end else
if (s = 'str') or (s = 'inlineStr') then begin if (s = 'str') or (s = 'inlineStr') then begin
// literal string // literal string