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,32 +801,44 @@ 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
if IsDateTimeFormat(numFmt) then
begin begin
if not IsTimeIntervalFormat(numFmt) then // no correction of time origin for "time interval" format if IsDateTimeFormat(numFmt) then
number := ConvertExcelDateTimeToDateTime(number, FDateMode); begin
sheet.WriteDateTime(cell, number); if not IsTimeIntervalFormat(numFmt) then // no correction of time origin for "time interval" format
end number := ConvertExcelDateTimeToDateTime(number, FDateMode);
else if IsTextFormat(numFmt) then sheet.WriteDateTime(cell, number);
sheet.WriteText(cell, dataStr) end
else else if IsTextFormat(numFmt) then
sheet.WriteNumber(cell, number); sheet.WriteText(cell, dataStr)
else
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
sheet.WriteText(cell, FSharedStrings[sstIndex]);
// Read rich-text parameters from the stream stored in the Objects of the stringlist
if FSharedStrings.Objects[sstIndex] <> nil then
begin begin
ms := TMemoryStream(FSharedStrings.Objects[sstIndex]); sheet.WriteText(cell, FSharedStrings[sstIndex]);
ms.Position := 0; // Read rich-text parameters from the stream stored in the Objects of the stringlist
n := ms.ReadWord; // Count of array elements if FSharedStrings.Objects[sstIndex] <> nil then
SetLength(cell^.RichTextParams, n); begin
ms.ReadBuffer(cell^.RichTextParams[0], n*SizeOf(TsRichTextParam)); ms := TMemoryStream(FSharedStrings.Objects[sstIndex]);
end; ms.Position := 0;
n := ms.ReadWord; // Count of array elements
SetLength(cell^.RichTextParams, n);
ms.ReadBuffer(cell^.RichTextParams[0], n*SizeOf(TsRichTextParam));
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