ReoGrid
DOCUMENT
Clipboard

Built-in Clipboard Support

  • Copy tabbed plain-text between ReoGrid and other spreadsheet application
  • Copy worksheet content, including data, style, border etc. between two ReoGrid worksheets

Tabbed plain-text

Tabbed plain-text format is the general format that is used to carry data between two spreadsheet-like applications. Excel uses this format to put data as plain-text into clipboard:

A1 \\t B1 \\t C1 \\n
A2 \\t B2 \\t C2 \\n
A3 \\t B3 \\t C3 \\n

Copy data from Excel into Notepad.

Clipboard

Get the tabbed plain-text from Clipboard:

string text = Clipboard.GetText();

ReoGrid provides a method to help on parsing the tabbed format into object array:

object[,] data = RGUtility.ParseTabbedString(text);

Then set this object array on worksheet:

worksheet.SetRangeData(sheet.SelectionRange, data);

Convert range data into tabbed string

Use method StringifyRange of worksheet to convert a selected range into tabbed string.

string tabbedStr = worksheet.StringifyRange(worksheet.SelectionRange);

Manually paste from tabbed string

Use method PasteFromString to copy tabbed string from Clipboard onto worksheet. Return value appliedRange is the final result copied from worksheet.

var appliedRange = worksheet.PasteFromString(new CellPosition("A1"), Clipboard.GetText());

Prevent built-in clipboard operations

Worksheet will automatically process clipboard operations when Ctrl-C, Ctrl-V and Ctrl-X received from user. By handling clipboard events and setting IsCancelled as true to prevent the built-in operations.

Events during operation of clipboard:

  • BeforeCopy
  • AfterCopy
  • BeforePaste
  • AfterPaste
  • BeforeCut
  • AfterCut

All Before-prefixed events have the property IsCancelled that can prevents default clipboard operations. For example:

worksheet.BeforePaste += (s, e) => e.IsCancelled = true;

Call clipboard methods

Methods to check whether or not a clipboard operation can be performed:

MethodDescription
bool CanCopy()Check whether or not can copy content into clipboard
bool CanPaste()Check whether or not can paste content from clipboard into worksheet (identifiable data existed in clipboard)
bool CanCut()Check whether or not can copy and remove content into clipboard

Methods to do clipboard operation:

bool Copy();
bool Paste();
bool Cut();

For example:

worksheet.Copy();

Manually copy and paste range

Use the method GetPartialGrid to get a content of range, use method SetPartialGrid copy the content to specified range.

var content = worksheet.GetPartialGrid("A1:B2");
worksheet.SetPartialGrid("C1:D2", content);

Was the content of the page helpful?

© 2012-2024UNVELL Inc.