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
This commit is contained in:
wp_xxyyzz
2015-09-24 17:35:38 +00:00
parent 39b73bcfec
commit 86b7e99ac9
3 changed files with 21 additions and 10 deletions

View File

@ -731,7 +731,8 @@ type
{ Clipboard } { Clipboard }
procedure CopyToClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat); procedure CopyToClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat);
procedure PasteFromClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat); procedure PasteFromClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat;
AOperation: TsCopyOperation);
(* (*
{ Color handling } { Color handling }
function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String; function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String;
@ -7807,7 +7808,7 @@ end;
calling routine since fpspreadsheet does not "know" the system's clipboard. calling routine since fpspreadsheet does not "know" the system's clipboard.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbook.PasteFromClipboardStream(AStream: TStream; procedure TsWorkbook.PasteFromClipboardStream(AStream: TStream;
AFormat: TsSpreadsheetFormat); AFormat: TsSpreadsheetFormat; AOperation: TsCopyOperation);
var var
clipbook: TsWorkbook; clipbook: TsWorkbook;
clipsheet: TsWorksheet; clipsheet: TsWorksheet;
@ -7815,7 +7816,7 @@ var
selArray: TsCellRangeArray; selArray: TsCellRangeArray;
r, c: LongInt; r, c: LongInt;
dr, dc: LongInt; dr, dc: LongInt;
srccell, destcell: PCell; srcCell, destCell: PCell;
i, n: Integer; i, n: Integer;
begin begin
if AStream = nil then if AStream = nil then
@ -7824,6 +7825,9 @@ begin
if ActiveWorksheet = nil then if ActiveWorksheet = nil then
exit; exit;
if AOperation = coNone then
exit;
// Create workbook into which the clipboard stream will write // Create workbook into which the clipboard stream will write
clipbook := TsWorkbook.Create; clipbook := TsWorkbook.Create;
try try
@ -7838,12 +7842,17 @@ begin
dc := LongInt(ActiveWorksheet.ActiveCellCol) - clipsheet.GetFirstColIndex(true); dc := LongInt(ActiveWorksheet.ActiveCellCol) - clipsheet.GetFirstColIndex(true);
// Copy cells from temporary workbook to active worksheet. // Copy cells from temporary workbook to active worksheet.
// Shift them such that the top/left cell of temp sheet is at the active cell. // 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 begin
r := LongInt(srcCell.Row) + dr; r := LongInt(srcCell.Row) + dr;
c := LongInt(srcCell.Col) + dc; c := LongInt(srcCell.Col) + dc;
destcell := ActiveWorksheet.GetCell(r, c); destCell := ActiveWorksheet.GetCell(r, c);
ActiveWorksheet.CopyCell(srccell, destcell); 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; end;
// Select the same cells as in the clipboard // Select the same cells as in the clipboard
n := clipsheet.GetSelectionCount; n := clipsheet.GetSelectionCount;

View File

@ -48,9 +48,6 @@ type
controls and describes which items have changed in the spreadsheet. } controls and describes which items have changed in the spreadsheet. }
TsNotificationItems = set of TsNotificationItem; TsNotificationItems = set of TsNotificationItem;
{@@ Identifier for an copy operation }
TsCopyOperation = (coNone, coCopyFormat, coCopyValue, coCopyFormula, coCopyCell);
{ TsWorkbookSource } { TsWorkbookSource }
{@@ TsWorkbookSource links a workbook to the visual spreadsheet controls and {@@ 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. 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 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. 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); procedure TsWorkbookSource.PasteCellsFromClipboard(AItem: TsCopyOperation);
var var
@ -1262,7 +1262,7 @@ begin
stream := TMemoryStream.Create; stream := TMemoryStream.Create;
try try
Clipboard.GetFormat(cf, stream); Clipboard.GetFormat(cf, stream);
FWorkbook.PasteFromClipboardStream(stream, fmt); FWorkbook.PasteFromClipboardStream(stream, fmt, AItem);
// To do: HTML format, CSV format, XML format, TEXT format // To do: HTML format, CSV format, XML format, TEXT format
// I don't know which format is written by xlsx and ods natively. // I don't know which format is written by xlsx and ods natively.

View File

@ -730,6 +730,8 @@ type
Options: TsReplaceOptions; Options: TsReplaceOptions;
end; end;
{@@ Identifier for a copy operation }
TsCopyOperation = (coNone, coCopyFormat, coCopyValue, coCopyFormula, coCopyCell);
implementation implementation