From ae6b7cc7f16facb190ec070676beaf906a3100a3 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 5 Mar 2019 11:32:48 +0000 Subject: [PATCH] fpspreadsheet: Enable/disable workbook notifications and formula recalculations in WorksheetGrid.BeginUpdate/EndUpdate. See https://forum.lazarus.freepascal.org/index.php/topic,44547.msg313254. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6825 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/visual/fpspreadsheetgrid.pas | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index c47668913..4edacc8db 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -1499,6 +1499,8 @@ end; procedure TsCustomWorksheetGrid.BeginUpdate; begin inc(FLockCount); + Workbook.DisableNotifications; + Workbook.LockFormulas; inherited BeginUpdate; end; @@ -3357,6 +3359,8 @@ end; procedure TsCustomWorksheetGrid.EndUpdate(ARefresh: Boolean = true); begin inherited EndUpdate(false); + Workbook.UnlockFormulas; + Workbook.EnableNotifications; dec(FLockCount); if (FLockCount = 0) and ARefresh then VisualChange; @@ -6627,9 +6631,13 @@ begin Worksheet.WriteFormula(r, c, Copy(s, 2, Length(s)), true) else begin - cell := Worksheet.GetCell(r, c); - HTMLToRichText(Workbook, Worksheet.ReadCellFont(cell), s, plain, rtParams); - Worksheet.WriteText(cell, plain, rtParams); // This will erase a non-formatted cell if s = '' + if cell = nil then cell := Worksheet.GetCell(r, c); + if s = '' then + Worksheet.WriteBlank(cell) + else begin + HTMLToRichText(Workbook, Worksheet.ReadCellFont(cell), s, plain, rtParams); + Worksheet.WriteText(cell, plain, rtParams); // This will erase a non-formatted cell if s = '' + end; end; end else if VarIsType(AValue, varDate) then