fpspreadsheet: Add exception handling for CF expressions writing to the workbook's error log.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7542 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-07-15 17:00:21 +00:00
parent 269c684533
commit 0e392dfcaa
5 changed files with 35 additions and 11 deletions

View File

@ -49,7 +49,7 @@
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Exceptions Count="5">
<Item1>
<Name Value="EAbort"/>
</Item1>
@ -59,6 +59,12 @@
<Item3>
<Name Value="EFOpenError"/>
</Item3>
<Item4>
<Name Value="EGeneralExprParserError"/>
</Item4>
<Item5>
<Name Value="EExprParser"/>
</Item5>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -48,7 +48,7 @@ begin
sh.WriteFormula(i, 18, '=1.0/1.0');
end;
lastCol := 18;
(*
// conditional format #1: equal to number constant
sh.WriteText(row, 0, 'equal to constant 5');
sh.WriteText(row, 1, 'background yellow');
@ -264,7 +264,7 @@ begin
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
fmtIdx := wb.AddCellFormat(fmt);
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcNotContainsErrors, fmtIdx);
*)
// conditional format: expression
inc(row);
sh.WriteText(row, 0, 'expression: ISNUMBER($E$5)');
@ -272,7 +272,7 @@ begin
InitFormatRecord(fmt);
fmt.SetBackgroundColor(scBlue);
fmtIdx := wb.AddCellFormat(fmt);
sh.WriteConditionalCellFormat(Range(row, 2, row, 2), cfcExpression, '=ISNUMBER($E$5)', fmtIdx);
sh.WriteConditionalCellFormat(Range(row, 2, row, 2), cfcExpression, '=IS-NUMBER($E$5)', fmtIdx);
// Two rules in the same conditional format
inc(row);

View File

@ -78,6 +78,8 @@ const
];
type
EGeneralExprParserError = Exception;
// Forward declarations
TsExpressionParser = class;
TsBuiltInExpressionManager = class;
@ -672,7 +674,7 @@ type
property SheetnameTerminator: char read FSheetNameTerminator write FSheetNameTerminator;
end;
EExprScanner = class(Exception);
EExprScanner = class(EGeneralExprParserError);
PFormatSettings = ^TFormatSettings;
{ TsExpressionParser }
@ -833,8 +835,8 @@ type
PsFormula = ^TsFormula;
{ Exception classes }
EExprParser = class(Exception);
ECalcEngine = class(Exception);
EExprParser = class(EGeneralExprParserError);
ECalcEngine = class(EGeneralExprParserError);
function TokenName(AToken: TsTokenType): String;
function ResultTypeName(AResult: TsResultType): String;

View File

@ -436,8 +436,16 @@ begin
begin
parser := TsSpreadsheetParser.Create(AWorksheet);
try
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
Result := parser.Expression[fdOpenDocument]; // Convert to ODS dialect
try
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
Result := parser.Expression[fdOpenDocument]; // Convert to ODS dialect
except
on EGeneralExprParserError do
begin
Result := VarToStr(v);
AWorksheet.Workbook.AddErrorMsg('Error in CF Expression ' + Result);
end;
end;
finally
parser.Free;
end;

View File

@ -289,8 +289,16 @@ begin
begin
parser := TsSpreadsheetParser.Create(AWorksheet);
try
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
Result := parser.R1C1Expression[nil]; // Convert to R1C1 dialect
try
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
Result := parser.R1C1Expression[nil]; // Convert to R1C1 dialect
except
on EGeneralExprParserError do
begin
Result := VarToStr(v);
AWorksheet.Workbook.AddErrorMsg('Error in CF Expression ' + Result);
end;
end;
// Note: Using nil here to get absolute references.
finally
parser.Free;