From 86b7e99ac90095dbc46fee030bae579e7c567b92 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 24 Sep 2015 17:35:38 +0000 Subject: [PATCH] fpspreadsheet: Paste cell, value, format or formula from clipboard git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4356 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpspreadsheet.pas | 21 +++++++++++++------ .../fpspreadsheet/fpspreadsheetctrls.pas | 8 +++---- components/fpspreadsheet/fpstypes.pas | 2 ++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index d8a6dfae0..2f7151d6a 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -731,7 +731,8 @@ type { Clipboard } procedure CopyToClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat); - procedure PasteFromClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat); + procedure PasteFromClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat; + AOperation: TsCopyOperation); (* { Color handling } function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String; @@ -7807,7 +7808,7 @@ end; calling routine since fpspreadsheet does not "know" the system's clipboard. -------------------------------------------------------------------------------} procedure TsWorkbook.PasteFromClipboardStream(AStream: TStream; - AFormat: TsSpreadsheetFormat); + AFormat: TsSpreadsheetFormat; AOperation: TsCopyOperation); var clipbook: TsWorkbook; clipsheet: TsWorksheet; @@ -7815,7 +7816,7 @@ var selArray: TsCellRangeArray; r, c: LongInt; dr, dc: LongInt; - srccell, destcell: PCell; + srcCell, destCell: PCell; i, n: Integer; begin if AStream = nil then @@ -7824,6 +7825,9 @@ begin if ActiveWorksheet = nil then exit; + if AOperation = coNone then + exit; + // Create workbook into which the clipboard stream will write clipbook := TsWorkbook.Create; try @@ -7838,12 +7842,17 @@ begin dc := LongInt(ActiveWorksheet.ActiveCellCol) - clipsheet.GetFirstColIndex(true); // Copy cells from temporary workbook to active worksheet. // Shift them such that the top/left cell of temp sheet is at the active cell. - for srccell in clipsheet.Cells do + for srcCell in clipsheet.Cells do begin r := LongInt(srcCell.Row) + dr; c := LongInt(srcCell.Col) + dc; - destcell := ActiveWorksheet.GetCell(r, c); - ActiveWorksheet.CopyCell(srccell, destcell); + destCell := ActiveWorksheet.GetCell(r, c); + case AOperation of + coCopyCell : ActiveWorksheet.CopyCell(srcCell, destCell); + coCopyValue : ActiveWorksheet.CopyValue(srcCell, destCell); + coCopyFormat : ActiveWorksheet.CopyFormat(srcCell, destCell); + coCopyFormula : ActiveWorksheet.CopyFormula(srcCell, destCell); + end; end; // Select the same cells as in the clipboard n := clipsheet.GetSelectionCount; diff --git a/components/fpspreadsheet/fpspreadsheetctrls.pas b/components/fpspreadsheet/fpspreadsheetctrls.pas index 3798199f3..07ed95dfc 100644 --- a/components/fpspreadsheet/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/fpspreadsheetctrls.pas @@ -48,9 +48,6 @@ type controls and describes which items have changed in the spreadsheet. } TsNotificationItems = set of TsNotificationItem; - {@@ Identifier for an copy operation } - TsCopyOperation = (coNone, coCopyFormat, coCopyValue, coCopyFormula, coCopyCell); - { TsWorkbookSource } {@@ TsWorkbookSource links a workbook to the visual spreadsheet controls and @@ -1225,6 +1222,9 @@ end; Pastes the cells stored in the internal list "Clipboard" into the worksheet. Using their stored row/col indexes the stored cells are translated such that the first stored cell appears at the currently active cell in the worksheet. + + AOperation determines which "item" of the cell (all, values, formats, formula) + is pasted. -------------------------------------------------------------------------------} procedure TsWorkbookSource.PasteCellsFromClipboard(AItem: TsCopyOperation); var @@ -1262,7 +1262,7 @@ begin stream := TMemoryStream.Create; try Clipboard.GetFormat(cf, stream); - FWorkbook.PasteFromClipboardStream(stream, fmt); + FWorkbook.PasteFromClipboardStream(stream, fmt, AItem); // To do: HTML format, CSV format, XML format, TEXT format // I don't know which format is written by xlsx and ods natively. diff --git a/components/fpspreadsheet/fpstypes.pas b/components/fpspreadsheet/fpstypes.pas index 45a5b3c39..f362eca10 100644 --- a/components/fpspreadsheet/fpstypes.pas +++ b/components/fpspreadsheet/fpstypes.pas @@ -730,6 +730,8 @@ type Options: TsReplaceOptions; end; + {@@ Identifier for a copy operation } + TsCopyOperation = (coNone, coCopyFormat, coCopyValue, coCopyFormula, coCopyCell); implementation