mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-07-08 18:16:08 +00:00
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.
45 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|