You've already forked lazarus-ccr
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:
@ -49,7 +49,7 @@
|
|||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<Exceptions Count="3">
|
<Exceptions Count="5">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Name Value="EAbort"/>
|
<Name Value="EAbort"/>
|
||||||
</Item1>
|
</Item1>
|
||||||
@ -59,6 +59,12 @@
|
|||||||
<Item3>
|
<Item3>
|
||||||
<Name Value="EFOpenError"/>
|
<Name Value="EFOpenError"/>
|
||||||
</Item3>
|
</Item3>
|
||||||
|
<Item4>
|
||||||
|
<Name Value="EGeneralExprParserError"/>
|
||||||
|
</Item4>
|
||||||
|
<Item5>
|
||||||
|
<Name Value="EExprParser"/>
|
||||||
|
</Item5>
|
||||||
</Exceptions>
|
</Exceptions>
|
||||||
</Debugging>
|
</Debugging>
|
||||||
</CONFIG>
|
</CONFIG>
|
||||||
|
@ -48,7 +48,7 @@ begin
|
|||||||
sh.WriteFormula(i, 18, '=1.0/1.0');
|
sh.WriteFormula(i, 18, '=1.0/1.0');
|
||||||
end;
|
end;
|
||||||
lastCol := 18;
|
lastCol := 18;
|
||||||
|
(*
|
||||||
// conditional format #1: equal to number constant
|
// conditional format #1: equal to number constant
|
||||||
sh.WriteText(row, 0, 'equal to constant 5');
|
sh.WriteText(row, 0, 'equal to constant 5');
|
||||||
sh.WriteText(row, 1, 'background yellow');
|
sh.WriteText(row, 1, 'background yellow');
|
||||||
@ -264,7 +264,7 @@ begin
|
|||||||
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
|
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
|
||||||
fmtIdx := wb.AddCellFormat(fmt);
|
fmtIdx := wb.AddCellFormat(fmt);
|
||||||
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcNotContainsErrors, fmtIdx);
|
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcNotContainsErrors, fmtIdx);
|
||||||
|
*)
|
||||||
// conditional format: expression
|
// conditional format: expression
|
||||||
inc(row);
|
inc(row);
|
||||||
sh.WriteText(row, 0, 'expression: ISNUMBER($E$5)');
|
sh.WriteText(row, 0, 'expression: ISNUMBER($E$5)');
|
||||||
@ -272,7 +272,7 @@ begin
|
|||||||
InitFormatRecord(fmt);
|
InitFormatRecord(fmt);
|
||||||
fmt.SetBackgroundColor(scBlue);
|
fmt.SetBackgroundColor(scBlue);
|
||||||
fmtIdx := wb.AddCellFormat(fmt);
|
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
|
// Two rules in the same conditional format
|
||||||
inc(row);
|
inc(row);
|
||||||
|
@ -78,6 +78,8 @@ const
|
|||||||
];
|
];
|
||||||
|
|
||||||
type
|
type
|
||||||
|
EGeneralExprParserError = Exception;
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
TsExpressionParser = class;
|
TsExpressionParser = class;
|
||||||
TsBuiltInExpressionManager = class;
|
TsBuiltInExpressionManager = class;
|
||||||
@ -672,7 +674,7 @@ type
|
|||||||
property SheetnameTerminator: char read FSheetNameTerminator write FSheetNameTerminator;
|
property SheetnameTerminator: char read FSheetNameTerminator write FSheetNameTerminator;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
EExprScanner = class(Exception);
|
EExprScanner = class(EGeneralExprParserError);
|
||||||
PFormatSettings = ^TFormatSettings;
|
PFormatSettings = ^TFormatSettings;
|
||||||
|
|
||||||
{ TsExpressionParser }
|
{ TsExpressionParser }
|
||||||
@ -833,8 +835,8 @@ type
|
|||||||
PsFormula = ^TsFormula;
|
PsFormula = ^TsFormula;
|
||||||
|
|
||||||
{ Exception classes }
|
{ Exception classes }
|
||||||
EExprParser = class(Exception);
|
EExprParser = class(EGeneralExprParserError);
|
||||||
ECalcEngine = class(Exception);
|
ECalcEngine = class(EGeneralExprParserError);
|
||||||
|
|
||||||
function TokenName(AToken: TsTokenType): String;
|
function TokenName(AToken: TsTokenType): String;
|
||||||
function ResultTypeName(AResult: TsResultType): String;
|
function ResultTypeName(AResult: TsResultType): String;
|
||||||
|
@ -436,8 +436,16 @@ begin
|
|||||||
begin
|
begin
|
||||||
parser := TsSpreadsheetParser.Create(AWorksheet);
|
parser := TsSpreadsheetParser.Create(AWorksheet);
|
||||||
try
|
try
|
||||||
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
|
try
|
||||||
Result := parser.Expression[fdOpenDocument]; // Convert to ODS dialect
|
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
|
finally
|
||||||
parser.Free;
|
parser.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -289,8 +289,16 @@ begin
|
|||||||
begin
|
begin
|
||||||
parser := TsSpreadsheetParser.Create(AWorksheet);
|
parser := TsSpreadsheetParser.Create(AWorksheet);
|
||||||
try
|
try
|
||||||
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
|
try
|
||||||
Result := parser.R1C1Expression[nil]; // Convert to R1C1 dialect
|
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.
|
// Note: Using nil here to get absolute references.
|
||||||
finally
|
finally
|
||||||
parser.Free;
|
parser.Free;
|
||||||
|
Reference in New Issue
Block a user