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:
parent
39b73bcfec
commit
86b7e99ac9
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -730,6 +730,8 @@ type
|
||||
Options: TsReplaceOptions;
|
||||
end;
|
||||
|
||||
{@@ Identifier for a copy operation }
|
||||
TsCopyOperation = (coNone, coCopyFormat, coCopyValue, coCopyFormula, coCopyCell);
|
||||
|
||||
|
||||
implementation
|
||||
|
Loading…
Reference in New Issue
Block a user