From 93ebcc497e308c60322f77378889b4796c29bbc9 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 1 Jan 2020 23:43:41 +0000 Subject: [PATCH] fpspreadsheet: Fix cell offset when pasting in from clipboard. Patch by DonAlfredo, https://forum.lazarus.freepascal.org/index.php/topic,47965.0.html git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7214 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/fpspreadsheet.pas | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 2e861d74e..1fc762d78 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -10383,6 +10383,7 @@ var clipbook: TsWorkbook; clipsheet: TsWorksheet; sel: TsCellRange; + range: TsCellRangeArray; r, c: Cardinal; srccell, destcell: PCell; begin @@ -10412,8 +10413,9 @@ begin end; end; // Select the same cells as in the source workbook. - clipsheet.SetSelection(ActiveWorksheet.GetSelection); - clipsheet.SelectCell(ActiveWorksheet.ActiveCellRow, ActiveWorksheet.ActiveCellCol); + range := ActiveWorksheet.GetSelection; + clipsheet.SetSelection(range); + clipsheet.SelectCell(range[0].Row1, range[0].Col1); // Write this workbook to a stream. Set the parameter spClipboard to // indicate that this should be the special clipboard version of the stream. @@ -10488,8 +10490,8 @@ begin and (ActiveWorksheet.GetSelection[0].Row1 = ActiveWorksheet.GetSelection[0].Row2) then begin // Find offset of active cell to left/top cell in clipboard sheet - dr := LongInt(ActiveWorksheet.ActiveCellRow) - clipsheet.GetFirstRowIndex(true); - dc := LongInt(ActiveWorksheet.ActiveCellCol) - clipsheet.GetFirstColIndex(true); + dr := LongInt(ActiveWorksheet.ActiveCellRow) - clipsheet.ActiveCellRow; + dc := LongInt(ActiveWorksheet.ActiveCellCol) - clipsheet.ActiveCellCol; // Copy cells from clipboard sheet to active worksheet // Shift them such that top/left of clipboard sheet is at active cell for srcCell in clipsheet.Cells do @@ -10523,8 +10525,8 @@ begin c := clipsheet.ActiveCellCol; end else begin - r := sel.Row2; - c := sel.Col2; + r := LongInt(sel.Row2); + c := LongInt(sel.Col2); end; if (r <> -1) and (c <> -1) then ActiveWorksheet.SelectCell(r + dr, c + dc);