You've already forked lazarus-ccr
fpspreadsheet: Improve copying of multiple cells in the WorksheetGrid. Fix worksheet not deleting formula if a blank cell is written.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4054 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1887,7 +1887,6 @@ begin
|
|||||||
RemoveAndFreeCell(ACell^.Row, ACell^.Col);
|
RemoveAndFreeCell(ACell^.Row, ACell^.Col);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Internal call-back procedure for looping through all cells when deleting
|
Internal call-back procedure for looping through all cells when deleting
|
||||||
a specified column. Deletion happens in DeleteCol BEFORE this callback!
|
a specified column. Deletion happens in DeleteCol BEFORE this callback!
|
||||||
@ -3713,7 +3712,7 @@ end;
|
|||||||
On formats that don't support unicode, the text will be converted
|
On formats that don't support unicode, the text will be converted
|
||||||
to ISO Latin 1.
|
to ISO Latin 1.
|
||||||
|
|
||||||
@param ACell Poiner to the cell
|
@param ACell Pointer to the cell
|
||||||
@param AText The text to be written encoded in utf-8
|
@param AText The text to be written encoded in utf-8
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorksheet.WriteUTF8Text(ACell: PCell; AText: ansistring);
|
procedure TsWorksheet.WriteUTF8Text(ACell: PCell; AText: ansistring);
|
||||||
@ -3938,6 +3937,7 @@ end;
|
|||||||
procedure TsWorksheet.WriteBlank(ACell: PCell);
|
procedure TsWorksheet.WriteBlank(ACell: PCell);
|
||||||
begin
|
begin
|
||||||
if ACell <> nil then begin
|
if ACell <> nil then begin
|
||||||
|
ACell^.FormulaValue := '';
|
||||||
if HasHyperlink(ACell) then
|
if HasHyperlink(ACell) then
|
||||||
WriteUTF8Text(ACell, '') // '' will be replaced by the hyperlink target.
|
WriteUTF8Text(ACell, '') // '' will be replaced by the hyperlink target.
|
||||||
else
|
else
|
||||||
@ -4001,7 +4001,7 @@ end;
|
|||||||
string, the worksheet tries to guess whether it is a number, a date/time or
|
string, the worksheet tries to guess whether it is a number, a date/time or
|
||||||
a text and calls the corresponding writing method.
|
a text and calls the corresponding writing method.
|
||||||
|
|
||||||
@param ACell Poiner to the cell
|
@param ACell Pointer to the cell
|
||||||
@param AValue Value to be written into the cell given as a string. Depending
|
@param AValue Value to be written into the cell given as a string. Depending
|
||||||
on the structure of the string, however, the value is written
|
on the structure of the string, however, the value is written
|
||||||
as a number, a date/time or a text.
|
as a number, a date/time or a text.
|
||||||
|
@ -467,6 +467,7 @@ end;
|
|||||||
type
|
type
|
||||||
TsCellList = class(TList)
|
TsCellList = class(TList)
|
||||||
private
|
private
|
||||||
|
FMultipleRanges: Boolean;
|
||||||
function GetCell(AIndex: Integer): PCell;
|
function GetCell(AIndex: Integer): PCell;
|
||||||
procedure SetCell(AIndex: Integer; ACell: PCell);
|
procedure SetCell(AIndex: Integer; ACell: PCell);
|
||||||
public
|
public
|
||||||
@ -478,6 +479,7 @@ type
|
|||||||
procedure Delete(AIndex: Integer);
|
procedure Delete(AIndex: Integer);
|
||||||
function IndexOf(ACell: PCell): Integer;
|
function IndexOf(ACell: PCell): Integer;
|
||||||
property CellByIndex[AIndex: Integer]: PCell read GetCell write SetCell;
|
property CellByIndex[AIndex: Integer]: PCell read GetCell write SetCell;
|
||||||
|
property MultipleRanges: Boolean read FMultipleRanges write FMultipleRanges;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -1086,6 +1088,7 @@ end;
|
|||||||
procedure TsWorkbookSource.ClearCellClipboard;
|
procedure TsWorkbookSource.ClearCellClipboard;
|
||||||
begin
|
begin
|
||||||
CellClipboard.Clear;
|
CellClipboard.Clear;
|
||||||
|
CellClipboard.MultipleRanges := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@ -1115,6 +1118,8 @@ begin
|
|||||||
else
|
else
|
||||||
CellClipboard.AddCell(cell);
|
CellClipboard.AddCell(cell);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
CellClipboard.MultipleRanges := (Length(sel) > 1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@ -1137,9 +1142,12 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorkbookSource.PasteCellsFromClipboard(AItem: TsCopyOperation);
|
procedure TsWorkbookSource.PasteCellsFromClipboard(AItem: TsCopyOperation);
|
||||||
var
|
var
|
||||||
r, c, dr, dc: LongInt;
|
r, c, dr, dc, destRow, destCol: LongInt;
|
||||||
i: Integer;
|
i, j: Integer;
|
||||||
cell: PCell;
|
cell: PCell;
|
||||||
|
baserng, rng: TsCellRange;
|
||||||
|
nc, nr: Integer;
|
||||||
|
baseRow, baseCol: Cardinal;
|
||||||
begin
|
begin
|
||||||
if CellClipboard.Count = 0 then
|
if CellClipboard.Count = 0 then
|
||||||
exit;
|
exit;
|
||||||
@ -1160,9 +1168,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
cell := CellClipboard.CellByIndex[0];
|
cell := CellClipboard.CellByIndex[0];
|
||||||
dr := FWorksheet.ActiveCellRow - cell^.Row;
|
baseRow := cell^.Row;
|
||||||
dc := FWorksheet.ActiveCellCol - cell^.Col;
|
baseCol := cell^.Col;
|
||||||
|
|
||||||
|
if CellClipboard.MultipleRanges then
|
||||||
|
begin
|
||||||
|
dr := FWorksheet.ActiveCellRow - baseRow;
|
||||||
|
dc := FWorksheet.ActiveCellCol - baseCol;
|
||||||
for i:=0 to CellClipboard.Count-1 do
|
for i:=0 to CellClipboard.Count-1 do
|
||||||
begin
|
begin
|
||||||
cell := CellClipboard.CellByIndex[i];
|
cell := CellClipboard.CellByIndex[i];
|
||||||
@ -1177,7 +1189,52 @@ begin
|
|||||||
FWorksheet.CopyFormula(cell, LongInt(cell^.Row) + dr, LongInt(cell^.Col) + dc);
|
FWorksheet.CopyFormula(cell, LongInt(cell^.Row) + dr, LongInt(cell^.Col) + dc);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
// Determine cell range enclosed by cells in clipboard
|
||||||
|
baserng.Row1 := MaxInt;
|
||||||
|
baserng.Col1 := MaxInt;
|
||||||
|
baserng.Row2 := 0;
|
||||||
|
baserng.Col2 := 0;
|
||||||
|
for i :=0 to CellClipboard.Count-1 do
|
||||||
|
begin
|
||||||
|
cell := CellClipboard.CellByIndex[i];
|
||||||
|
baserng.Row1 := Min(baserng.Row1, cell^.Row);
|
||||||
|
baserng.Row2 := Max(baserng.Row2, cell^.Row);
|
||||||
|
baserng.Col1 := Min(baserng.Col1, cell^.Col);
|
||||||
|
baserng.Col2 := Max(baserng.Col2, cell^.Col);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Each selected range of the worksheet gets tiled copies of the range of
|
||||||
|
// the cells in clipboard
|
||||||
|
for j:=0 to FWorksheet.GetSelectionCount-1 do
|
||||||
|
begin
|
||||||
|
rng := FWorksheet.GetSelection[j];
|
||||||
|
r := rng.Row1;
|
||||||
|
while (r <= rng.Row2) do begin
|
||||||
|
c := rng.Col1;
|
||||||
|
while (c <= rng.Col2) do begin
|
||||||
|
for i:=0 to CellClipboard.Count-1 do begin
|
||||||
|
cell := CellClipboard.CellByIndex[i];
|
||||||
|
destRow := r + LongInt(cell^.Row) - baserng.Row1;
|
||||||
|
destCol := c + LongInt(cell^.Col) - baserng.Col1;
|
||||||
|
case AItem of
|
||||||
|
coCopyCell:
|
||||||
|
FWorksheet.CopyCell(cell^.Row, cell^.Col, destRow, destCol);
|
||||||
|
coCopyValue:
|
||||||
|
FWorksheet.CopyValue(cell, destRow, destCol);
|
||||||
|
coCopyFormat:
|
||||||
|
FWorksheet.CopyFormat(cell, destRow, destCol);
|
||||||
|
coCopyFormula:
|
||||||
|
FWorksheet.CopyFormula(cell, destRow, destCol);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
inc(c, baserng.Col2 - baserng.Col1 + 1);
|
||||||
|
end;
|
||||||
|
inc(r, baserng.Row2 - baserng.Row1 + 1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
EnableControls;
|
EnableControls;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user