A copy puts two formats on the clipboard at once.
| Format | What it is for |
|---|---|
| TSV (tab-separated text) | Interoperating with Excel, text editors and the rest |
HTML carrying data-rg-* attributes | ReoGrid to ReoGrid (styles, formulas and merges survive) |
The paste side prefers the HTML when it is there and falls back to interpreting the TSV. reogrid-web (the web edition) uses the same scheme, so pasting between the two works.
The file format (reogrid-json) is never used on the clipboard.
From the UI
| Member | What it does |
|---|---|
control.CopySelection() | Copies the selection |
control.CutSelection() | Cuts |
control.PasteClipboard() | Pastes |
Ctrl+C / Ctrl+X / Ctrl+V are wired up by default.
From the API
using unvell.ReoGrid.Core.Clipboard;
// turn the selection into TSV (ready to paste into Excel or a text editor)
string tsv = RangeClipboard.BuildTsv(ws, RangePosition.Parse("A1:C10"));
// read TSV in
ClipboardRangeData data = RangeClipboard.ParseTsv(tsv);
RangePosition pasted = RangeClipboard.Apply(ws, startRow: 20, startCol: 0, data);
These never touch the system clipboard, so they work headless too.
Inspecting what was parsed
Console.WriteLine($"{data.Rows} x {data.Columns}");
// styles and formulas come back too when the HTML was written by ReoGrid
if (data.IsReoGridSource)
Console.WriteLine($"anchor = {data.SourceAnchorRow},{data.SourceAnchorCol}");
ClipboardCellData? cell = data.Cells[0][0];
if (cell != null)
Console.WriteLine($"{cell.Value} fmt={cell.NumberFormat} span={cell.RowSpan}x{cell.ColSpan}");
What ClipboardCellData carries.
| Property | What it is |
|---|---|
Value | The input string (a formula when it starts with =) |
NumberFormat | The number format |
Style | The style |
RichText | Rich text |
CellType | The cell type’s settings |
RowSpan / ColSpan | Merging |
Parsed from TSV, only Value is filled in.
Copying a multiple selection
The clipboard is a rectangle, so copying a multiple selection only goes through when the areas pack into one block. The rule is Excel’s.
| How the areas sit | Allowed |
|---|---|
Sharing their columns, stacked vertically (A1:C3 and A7:C9) | ✅ concatenated top to bottom |
Sharing their rows, side by side (A1:A5 and D1:D5) | ✅ concatenated left to right |
| Anything else | ❌ refused |
The refusal carries Excel’s own sentence,
“That command cannot be used on multiple selections.”
(RangeClipboard.MultiRangeCopyMessage). Copying the bounding box instead would quietly hand
back cells nobody selected, so nothing is guessed at.
Ask first with RangeClipboard.TryGetCopyLayout(areas, out var ordered, out bool stacked).
BuildTsv and BuildHtmlFragment both take a list of ranges as well as a single one.
Relative references offset automatically
Copying a cell containing a formula and pasting it elsewhere shifts the relative references to suit the destination. Same as Excel and V4.
C1 holds "=A1*B1"; copy C1 and paste at C5
-> C5 becomes "=A5*B5"
What makes this work is the anchor information in the HTML (SourceAnchorRow /
SourceAnchorCol). Because the source position is recorded, references can be shifted by
exactly the difference to the paste position.
When several areas were packed into one block, a cell’s position in the block no longer says
where it came from. Each cell then carries data-rg-src (SourceRow / SourceCol) and its
references shift from its own source instead. A single-range copy emits no such attribute,
so that output stays byte-identical to what it always was.
References pinned with $ do not move. A reference that would leave the sheet becomes
#REF!.
Interoperating with Excel
| Direction | What survives |
|---|---|
| Excel → ReoGrid | values, as TSV |
| ReoGrid → Excel | values, as TSV |
| ReoGrid → ReoGrid | styles, formulas and merges too, via HTML |
| reogrid-web → ReoGrid One | via HTML (the same attribute format) |
Undo
Pasting is recorded in the history. A two-step operation such as cut-then-paste undoes as a single step.