You've already forked lazarus-ccr
fpspreadsheet: Allow localized decimal and list separators in formula editor of the spready demo
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3514 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -4,7 +4,7 @@ object Form1: TForm1
|
||||
Top = 258
|
||||
Width = 884
|
||||
Caption = 'spready'
|
||||
ClientHeight = 619
|
||||
ClientHeight = 614
|
||||
ClientWidth = 884
|
||||
Menu = MainMenu
|
||||
OnActivate = FormActivate
|
||||
@ -14,7 +14,7 @@ object Form1: TForm1
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Height = 78
|
||||
Top = 541
|
||||
Top = 536
|
||||
Width = 884
|
||||
Align = alBottom
|
||||
BevelOuter = bvNone
|
||||
@ -23,9 +23,9 @@ object Form1: TForm1
|
||||
TabOrder = 0
|
||||
object CbShowHeaders: TCheckBox
|
||||
Left = 8
|
||||
Height = 19
|
||||
Height = 24
|
||||
Top = 8
|
||||
Width = 93
|
||||
Width = 116
|
||||
Caption = 'Show headers'
|
||||
Checked = True
|
||||
OnClick = CbShowHeadersClick
|
||||
@ -34,9 +34,9 @@ object Form1: TForm1
|
||||
end
|
||||
object CbShowGridLines: TCheckBox
|
||||
Left = 8
|
||||
Height = 19
|
||||
Height = 24
|
||||
Top = 39
|
||||
Width = 100
|
||||
Width = 125
|
||||
Caption = 'Show grid lines'
|
||||
Checked = True
|
||||
OnClick = CbShowGridLinesClick
|
||||
@ -45,7 +45,7 @@ object Form1: TForm1
|
||||
end
|
||||
object EdFrozenCols: TSpinEdit
|
||||
Left = 645
|
||||
Height = 23
|
||||
Height = 28
|
||||
Top = 8
|
||||
Width = 52
|
||||
OnChange = EdFrozenColsChange
|
||||
@ -53,7 +53,7 @@ object Form1: TForm1
|
||||
end
|
||||
object EdFrozenRows: TSpinEdit
|
||||
Left = 645
|
||||
Height = 23
|
||||
Height = 28
|
||||
Top = 39
|
||||
Width = 52
|
||||
OnChange = EdFrozenRowsChange
|
||||
@ -61,37 +61,37 @@ object Form1: TForm1
|
||||
end
|
||||
object Label1: TLabel
|
||||
Left = 560
|
||||
Height = 15
|
||||
Height = 20
|
||||
Top = 13
|
||||
Width = 62
|
||||
Width = 77
|
||||
Caption = 'Frozen cols:'
|
||||
FocusControl = EdFrozenCols
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
Left = 560
|
||||
Height = 15
|
||||
Height = 20
|
||||
Top = 40
|
||||
Width = 66
|
||||
Width = 82
|
||||
Caption = 'Frozen rows:'
|
||||
FocusControl = EdFrozenRows
|
||||
ParentColor = False
|
||||
end
|
||||
object CbReadFormulas: TCheckBox
|
||||
Left = 160
|
||||
Height = 19
|
||||
Height = 24
|
||||
Top = 8
|
||||
Width = 96
|
||||
Width = 120
|
||||
Caption = 'Read formulas'
|
||||
OnChange = CbReadFormulasChange
|
||||
TabOrder = 2
|
||||
end
|
||||
object CbHeaderStyle: TComboBox
|
||||
Left = 408
|
||||
Height = 23
|
||||
Height = 28
|
||||
Top = 8
|
||||
Width = 116
|
||||
ItemHeight = 15
|
||||
ItemHeight = 20
|
||||
ItemIndex = 2
|
||||
Items.Strings = (
|
||||
'Lazarus'
|
||||
@ -105,9 +105,9 @@ object Form1: TForm1
|
||||
end
|
||||
object CbAutoCalcFormulas: TCheckBox
|
||||
Left = 160
|
||||
Height = 19
|
||||
Height = 24
|
||||
Top = 39
|
||||
Width = 128
|
||||
Width = 158
|
||||
Caption = 'Calculate on change'
|
||||
OnChange = CbAutoCalcFormulasChange
|
||||
TabOrder = 3
|
||||
@ -115,7 +115,7 @@ object Form1: TForm1
|
||||
end
|
||||
object PageControl1: TPageControl
|
||||
Left = 0
|
||||
Height = 462
|
||||
Height = 457
|
||||
Top = 79
|
||||
Width = 648
|
||||
ActivePage = TabSheet1
|
||||
@ -125,11 +125,11 @@ object Form1: TForm1
|
||||
OnChange = PageControl1Change
|
||||
object TabSheet1: TTabSheet
|
||||
Caption = 'Sheet1'
|
||||
ClientHeight = 434
|
||||
ClientHeight = 424
|
||||
ClientWidth = 640
|
||||
object WorksheetGrid: TsWorksheetGrid
|
||||
Left = 0
|
||||
Height = 434
|
||||
Height = 424
|
||||
Top = 0
|
||||
Width = 640
|
||||
FrozenCols = 0
|
||||
@ -145,7 +145,7 @@ object Form1: TForm1
|
||||
TitleStyle = tsNative
|
||||
OnSelection = WorksheetGridSelection
|
||||
ColWidths = (
|
||||
42
|
||||
56
|
||||
64
|
||||
64
|
||||
64
|
||||
@ -263,19 +263,19 @@ object Form1: TForm1
|
||||
end
|
||||
object FontComboBox: TComboBox
|
||||
Left = 52
|
||||
Height = 23
|
||||
Height = 28
|
||||
Top = 2
|
||||
Width = 127
|
||||
ItemHeight = 15
|
||||
ItemHeight = 20
|
||||
OnSelect = FontComboBoxSelect
|
||||
TabOrder = 0
|
||||
end
|
||||
object FontSizeComboBox: TComboBox
|
||||
Left = 179
|
||||
Height = 23
|
||||
Height = 28
|
||||
Top = 2
|
||||
Width = 48
|
||||
ItemHeight = 15
|
||||
ItemHeight = 20
|
||||
Items.Strings = (
|
||||
'8'
|
||||
'9'
|
||||
@ -443,7 +443,7 @@ object Form1: TForm1
|
||||
end
|
||||
object InspectorSplitter: TSplitter
|
||||
Left = 648
|
||||
Height = 462
|
||||
Height = 457
|
||||
Top = 79
|
||||
Width = 5
|
||||
Align = alRight
|
||||
@ -451,7 +451,7 @@ object Form1: TForm1
|
||||
end
|
||||
object InspectorPageControl: TPageControl
|
||||
Left = 653
|
||||
Height = 462
|
||||
Height = 457
|
||||
Top = 79
|
||||
Width = 231
|
||||
ActivePage = PgCellValue
|
||||
@ -461,11 +461,11 @@ object Form1: TForm1
|
||||
OnChange = InspectorPageControlChange
|
||||
object PgCellValue: TTabSheet
|
||||
Caption = 'Cell value'
|
||||
ClientHeight = 434
|
||||
ClientHeight = 424
|
||||
ClientWidth = 223
|
||||
object CellInspector: TValueListEditor
|
||||
Left = 0
|
||||
Height = 434
|
||||
Height = 424
|
||||
Top = 0
|
||||
Width = 223
|
||||
Align = alClient
|
||||
|
@ -733,7 +733,7 @@ begin
|
||||
c := WorksheetGrid.GetWorksheetCol(WorksheetGrid.Col);
|
||||
s := EdFormula.Text;
|
||||
if (s <> '') and (s[1] = '=') then
|
||||
WorksheetGrid.Worksheet.WriteFormula(r, c, Copy(s, 2, Length(s)))
|
||||
WorksheetGrid.Worksheet.WriteFormula(r, c, Copy(s, 2, Length(s)), true)
|
||||
else
|
||||
WorksheetGrid.Worksheet.WriteCellValueAsString(r, c, EdFormula.Text);
|
||||
end;
|
||||
@ -899,7 +899,7 @@ begin
|
||||
|
||||
cell := WorksheetGrid.Worksheet.FindCell(r, c);
|
||||
if cell <> nil then begin
|
||||
s := WorksheetGrid.Worksheet.ReadFormulaAsString(cell);
|
||||
s := WorksheetGrid.Worksheet.ReadFormulaAsString(cell, true);
|
||||
if s <> '' then begin
|
||||
if s[1] <> '=' then s := '=' + s;
|
||||
EdFormula.Text := s;
|
||||
|
@ -560,7 +560,7 @@ type
|
||||
function ReadAsNumber(ACell: PCell): Double; overload;
|
||||
function ReadAsDateTime(ARow, ACol: Cardinal; out AResult: TDateTime): Boolean; overload;
|
||||
function ReadAsDateTime(ACell: PCell; out AResult: TDateTime): Boolean; overload;
|
||||
function ReadFormulaAsString(ACell: PCell): String;
|
||||
function ReadFormulaAsString(ACell: PCell; ALocalized: Boolean = false): String;
|
||||
function ReadNumericValue(ACell: PCell; out AValue: Double): Boolean;
|
||||
|
||||
{ Reading of cell attributes }
|
||||
@ -604,8 +604,10 @@ type
|
||||
function WriteErrorValue(ARow, ACol: Cardinal; AValue: TsErrorValue): PCell; overload;
|
||||
procedure WriteErrorValue(ACell: PCell; AValue: TsErrorValue); overload;
|
||||
|
||||
function WriteFormula(ARow, ACol: Cardinal; AFormula: String): PCell; overload;
|
||||
procedure WriteFormula(ACell: PCell; AFormula: String); overload;
|
||||
function WriteFormula(ARow, ACol: Cardinal; AFormula: String;
|
||||
ALocalized: Boolean = false): PCell; overload;
|
||||
procedure WriteFormula(ACell: PCell; AFormula: String;
|
||||
ALocalized: Boolean = false); overload;
|
||||
|
||||
function WriteNumber(ARow, ACol: Cardinal; ANumber: double): PCell; overload;
|
||||
procedure WriteNumber(ACell: PCell; ANumber: Double); overload;
|
||||
@ -2634,16 +2636,34 @@ end;
|
||||
{@@ If a cell contains a formula (string formula or RPN formula) the formula
|
||||
is returned as a string in Excel syntax.
|
||||
|
||||
@param ACell Pointer to the cell considered
|
||||
@param ACell Pointer to the cell considered
|
||||
@param ALocalized If true, the formula is returned with decimal and list
|
||||
separators accoding to the workbook's FormatSettings.
|
||||
Otherwise it uses dot and comma, respectively.
|
||||
@return Formula string in Excel syntax (does not contain a leading "=")
|
||||
}
|
||||
function TsWorksheet.ReadFormulaAsString(ACell: PCell): String;
|
||||
function TsWorksheet.ReadFormulaAsString(ACell: PCell;
|
||||
ALocalized: Boolean = false): String;
|
||||
var
|
||||
parser: TsSpreadsheetParser;
|
||||
begin
|
||||
Result := '';
|
||||
if ACell = nil then
|
||||
exit;
|
||||
if HasFormula(ACell) then
|
||||
Result := ACell^.FormulaValue;
|
||||
if HasFormula(ACell) then begin
|
||||
if ALocalized then
|
||||
begin
|
||||
parser := TsSpreadsheetParser.Create(self);
|
||||
try
|
||||
parser.Expression := ACell^.FormulaValue;
|
||||
Result := parser.LocalizedExpression[Workbook.FormatSettings];
|
||||
finally
|
||||
parser.Free;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Result := ACell^.FormulaValue;
|
||||
end;
|
||||
end;
|
||||
|
||||
{@@
|
||||
@ -3524,29 +3544,53 @@ end;
|
||||
@param ARow The row of the cell
|
||||
@param ACol The column of the cell
|
||||
@param AFormula The formula string to be written. A leading "=" will be removed.
|
||||
@param ALocalized If true, the formula is expected to have decimal and list
|
||||
separators of the workbook's FormatSettings. Otherwise
|
||||
uses dot and comma, respectively.
|
||||
@return Pointer to the cell
|
||||
}
|
||||
function TsWorksheet.WriteFormula(ARow, ACol: Cardinal; AFormula: string): PCell;
|
||||
function TsWorksheet.WriteFormula(ARow, ACol: Cardinal; AFormula: string;
|
||||
ALocalized: Boolean = false): PCell;
|
||||
begin
|
||||
Result := GetCell(ARow, ACol);
|
||||
WriteFormula(Result, AFormula);
|
||||
WriteFormula(Result, AFormula, ALocalized);
|
||||
end;
|
||||
|
||||
{@@
|
||||
Writes a formula to a given cell
|
||||
|
||||
@param ACell Pointer to the cell
|
||||
@param AFormula Formula string to be written. A leading '=' will be removed.
|
||||
@param ACell Pointer to the cell
|
||||
@param AFormula Formula string to be written. A leading '=' will be removed.
|
||||
@param ALocalized If true, the formula is expected to have decimal and list
|
||||
separators of the workbook's FormatSettings. Otherwise
|
||||
uses dot and comma, respectively.
|
||||
}
|
||||
procedure TsWorksheet.WriteFormula(ACell: PCell; AFormula: string);
|
||||
procedure TsWorksheet.WriteFormula(ACell: PCell; AFormula: string;
|
||||
ALocalized: Boolean = false);
|
||||
var
|
||||
parser: TsExpressionParser;
|
||||
begin
|
||||
if ACell = nil then
|
||||
exit;
|
||||
ACell^.ContentType := cctFormula;
|
||||
|
||||
// Remove '='; is not stored internally
|
||||
if (AFormula <> '') and (AFormula[1] = '=') then
|
||||
ACell^.FormulaValue := Copy(AFormula, 2, Length(AFormula))
|
||||
else
|
||||
ACell^.FormulaValue := AFormula;
|
||||
AFormula := Copy(AFormula, 2, Length(AFormula));
|
||||
|
||||
// Convert "localized" formula to standard format
|
||||
if ALocalized then begin
|
||||
parser := TsSpreadsheetParser.Create(self);
|
||||
try
|
||||
parser.LocalizedExpression[Workbook.FormatSettings] := AFormula;
|
||||
AFormula := parser.Expression;
|
||||
finally
|
||||
parser.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Store formula in cell
|
||||
ACell^.ContentType := cctFormula;
|
||||
ACell^.FormulaValue := AFormula;
|
||||
ChangedCell(ACell^.Row, ACell^.Col);
|
||||
end;
|
||||
|
||||
|
Reference in New Issue
Block a user