V4 V5

A copy puts two formats on the clipboard at once.

FormatWhat it is for
TSV (tab-separated text)Interoperating with Excel, text editors and the rest
HTML carrying data-rg-* attributesReoGrid 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

MemberWhat 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.

PropertyWhat it is
ValueThe input string (a formula when it starts with =)
NumberFormatThe number format
StyleThe style
RichTextRich text
CellTypeThe cell type’s settings
RowSpan / ColSpanMerging

Parsed from TSV, only Value is filled in.

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.

References pinned with $ do not move. A reference that would leave the sheet becomes #REF!.

Interoperating with Excel

DirectionWhat survives
Excel → ReoGridvalues, as TSV
ReoGrid → Excelvalues, as TSV
ReoGrid → ReoGridstyles, formulas and merges too, via HTML
reogrid-web → ReoGrid Onevia 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.

Was this article helpful?