fpspreadsheet: Fix issue when moving cells with formulas mentioned in previous commit.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8263 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-04-22 21:57:56 +00:00
parent e97d4c3c20
commit a64ed1654e

View File

@ -2276,6 +2276,7 @@ var
fromRow, fromCol: Cardinal;
sheet: TsWorksheet;
i: Integer;
formula: String;
begin
if ACell = nil then
exit;
@ -2289,7 +2290,16 @@ begin
fromCol := ACell^.Col;
// Copy cell to new location
// Note: In Excel the formula in a moved cell still points to the initial
// location. This is different from copying a formula.
// --> We must prevent CopyCell from adjusting the formula
// --> Erase the formula temporarily.
formula := ReadFormula(ACell);
DeleteFormula(ACell);
CopyCell(fromRow, fromCol, AToRow, AToCol);
// Restore the old formula which points to the old location.
if formula <> '' then
WriteFormula(AToRow, AToCol, formula);
// Fix formula references to this cell
for i := 0 to FWorkbook.GetWorksheetcount-1 do begin