fpspreadsheet: Include copying of row and column records in CopyWorksheetFrom.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5580 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2017-01-02 09:10:20 +00:00
parent fe87aadcd8
commit 587ea10dc8

View File

@ -388,6 +388,9 @@ type
procedure CopyValue(AFromCell, AToCell: PCell); overload;
procedure CopyValue(AValueCell: PCell; AToRow, AToCol: Cardinal); overload;
procedure CopyCol(AFromCol, AToCol: Cardinal; AFromWorksheet: TsWorksheet = nil);
procedure CopyRow(AFromRow, AToRow: Cardinal; AFromWorksheet: TsWorksheet = nil);
procedure Clear;
procedure DeleteCell(ACell: PCell);
procedure EraseCell(ACell: PCell);
@ -1905,6 +1908,74 @@ begin
CopyValue(AValueCell, GetCell(AToRow, AToCol));
end;
{@@ ----------------------------------------------------------------------------
Copies a column record to another location. The new column has the same
colwidth and the same formatting.
@param AFromCol Index of the column to be copied
@param AToCol Index of the destination column
-------------------------------------------------------------------------------}
procedure TsWorksheet.CopyCol(AFromCol, AToCol: Cardinal;
AFromWorksheet: TsWorksheet = nil);
var
srcCol, destCol: PCol;
begin
if AFromWorksheet = nil then
AFromWorksheet := self;
srcCol := AFromWorksheet.FindCol(AFromCol);
destCol := FindCol(AToCol);
// Overwrite destination column with empty column record ?
if (srcCol = nil) then
begin
if destCol <> nil then
DeleteCol(AToCol);
exit;
end;
// Create new or use existing column record
destCol := GetCol(AToCol);
// Copy contents of column record...
destCol^ := srcCol^;
// ... and restore column index lost in previous step
destCol^.Col := AToCol;
end;
{@@ ----------------------------------------------------------------------------
Copies a row record to another location. The new row has the same
row heightand the same formatting.
@param AFromRow Index of the row to be copied
@param AToTow Index of the destination row
-------------------------------------------------------------------------------}
procedure TsWorksheet.CopyRow(AFromRow, AToRow: Cardinal;
AFromWorksheet: TsWorksheet);
var
srcRow, destRow: PRow;
begin
if AFromWorksheet = nil then
AFromWorksheet := self;
srcRow := AFromWorksheet.FindRow(AFromRow);
destRow := FindRow(AToRow);
// Overwrite destination row with empty row record?
if (srcRow = nil) then
begin
if destRow <> nil then
DeleteRow(AToRow);
exit;
end;
// Create new or use existing row record
destRow := GetRow(AToRow);
// Copy contents of row record...
destRow^ := srcRow^;
// ... and restore row index lost in previous step
destRow^.Row := AToRow;
end;
procedure TsWorksheet.Clear;
begin
FCells.Clear;
@ -8158,6 +8229,9 @@ function TsWorkbook.CopyWorksheetFrom(AWorksheet: TsWorksheet;
var
r, c: Cardinal;
cell: PCell;
col: PCol;
row: PRow;
i: Integer;
begin
Result := nil;
if (AWorksheet = nil) then
@ -8172,6 +8246,18 @@ begin
c := cell^.Col;
Result.CopyCell(r, c, r, c, AWorksheet);
end;
for i := 0 to AWorksheet.Cols.Count-1 do
begin
col := AWorksheet.Cols[i];
c := col^.Col;
Result.CopyCol(c, c, AWorksheet);
end;
for i := 0 to AWorksheet.Rows.Count-1 do
begin
row := AWorksheet.Rows[i];
r := row^.Row;
Result.CopyRow(r, r, AWorksheet);
end;
finally
dec(FLockCount);
end;