Files
radzen-blazor/Radzen.Blazor/Spreadsheet/ClearContentsCommand.cs
Atanas Korchev 40d0583987 Transfer the full cell state in spreadsheet paste, cut and autofill
Formats, quote prefixes and hyperlinks are now copied, empty source
cells blank their destinations and cut clears the source, matching
Excel. Entering a value over a formula cell replaces the formula, quote
prefixed entries store literal text and undo restores cells exactly as
captured, including after redo.

Breaking change: RangeSnapshotCommandBase snapshots cells as detached
clones (Dictionary<CellRef, Cell?>) instead of a value/formula/format
tuple.
2026-07-06 12:21:20 +03:00

45 lines
1.1 KiB
C#

#nullable enable
using Radzen.Documents.Spreadsheet;
namespace Radzen.Blazor.Spreadsheet;
class ClearContentsCommand : RangeSnapshotCommandBase
{
public override SheetAction RequiredAction => SheetAction.EditCell;
public override SpreadsheetFeature? Feature => SpreadsheetFeature.Editing;
private readonly RangeRef range;
public ClearContentsCommand(Worksheet sheet, RangeRef range)
: base(sheet)
{
this.range = range;
}
protected override bool DoExecute()
{
for (var row = range.Start.Row; row <= range.End.Row; row++)
{
for (var column = range.Start.Column; column <= range.End.Column; column++)
{
if (sheet.Cells.TryGet(row, column, out var cell))
{
Capture(new CellRef(row, column));
// Deliberately not Cell.Clear: Excel's Clear Contents keeps formats.
cell.Formula = null;
cell.Value = null;
}
}
}
return snapshot.Count > 0;
}
public override void Unexecute()
{
RestoreSnapshot();
}
}