Clipboard

SetClipboard

WithInput names what to put on and SetClipboard is the action that puts it there, so the chain ends on the action the way every GPAL chain does. WithInput takes a string, a grid or a GPALFile. A grid goes on as tab separated lines, which is what a spreadsheet reads back as cells, so a GPAL grid pastes into Excel as a range rather than as one long string. A file puts its text on for every type except FileList, where the file itself goes on, which is what pasting into a folder expects, and Image, where the picture goes on rather than the bytes read as characters. An image can also go on from a string holding it as base64, which is the same string GetClipboard hands back, so an image taken off the clipboard goes back on unchanged. The type defaults to Text, so a plain string needs nothing said.

NOTE

Setting the clipboard is half of getting data into an application that has no usable input path. Put the value on the clipboard, focus the control, and send Control V. That is slower and cruder than FillInFrom and should not be the first choice, but it works on controls that expose no ValuePattern to write to.

Examples

GPAL Fluent: High-level fluent C# API

//SetClipboard takes the same optional ClipboardType as GetClipboard and defaults to Text. An image goes on from a file or from a base64 string, with or without a data URI in front of it, and not from ordinary text. Clear empties the clipboard and is its own action, needing no WithInput.

// text

GPAL.Clipboard

.WithInput("hello")

.SetClipboard();


// a grid, which pastes into a spreadsheet as cells

GPAL.Clipboard

.WithInput(rows)

.SetClipboard();


// a file's text

GPAL.Clipboard

.WithInput((GPALFile)"notes.txt")

.SetClipboard();


// the file itself, for pasting into a folder

GPAL.Clipboard

.WithInput((GPALFile)"report.pdf")

.SetClipboard(ClipboardType.FileList);


// an image

GPAL.Clipboard

.WithInput((GPALFile)"shot.png")

.SetClipboard(ClipboardType.Image);


// an image from base64, the string GetClipboard gives back

GPAL.Clipboard

.WithInput(encoded)

.SetClipboard(ClipboardType.Image);


// and emptying it

GPAL.Clipboard.Clear();

💬 Ask GPAL