Text - The easiest way to copy text to the clipboard

If you want app users to be able to copy the contents of an app to the clipboard, the new Copy function makes this task super simple!

In the past, there wasn't a simple way to allow users to copy app contents to the clipboard. Building this functionality would involve writing a PCF control.

The good news is that following an update to Power Apps, we can now copy text content directly to the clipboard by calling the Copy function. The formula below illustrates the simple use of this function - this copies the literal text abc to the clipboard.

The full documentation for the copy function is here:

To extned on this, here are use case examples of how to apply this function in a working app.

How to copy label text to the clipboard

A typical scenario is to copy label text to the clipboard. For example, we may want to allow users to copy a code or a long reference number.

The illustrate how this would look, let's take the label on a form control. To enable users to copy the 'address1' value by clicking on the lable, we would set the OnSelect property of the label to the following: 


This example also highlights another important step when working with items on a form. We must set the DisplayMode property of the parent card to DisplayMode.Edit. If we don't do this, nothing will happen when the user clicks the label.

In this example, we can additionally set the Tooltip property to a value such as "Click here to copy to clipboard" to help inform the user that clicking the label will copy its contents to the clipboard.

Copying a single column of data from a gallery to the clipboard

Another use case scenario is to copy multiple values to  the clipboard, say from a gallery.

Let's take the example of the gallery shown beneath. To copy the contents of all the "address1" values that have been loaded into the gallery, we can add button and apply the following formula:

Address1 & Char(10)
This formula will copy all "address 1" values, with each item separated with a line break (Char(10)).

Copying multiple columns of data from a gallery to the clipboard

As an extension of the above, here's an adaptation to copy multiple fields from each row a gallery to the clipboard. In this example, we'll copy the fields "address1", "City", and "Postcode".

The formula would look like this:

Address1 & Char(9) & City & Char(9) & Postcode & Char(10)

Here, we separate each field with a tab character (Char(9)).

By doing this, users can go into Excel and press Ctrl-V to paste the contents into a speadsheet. By default, Excel recognises the tab character as a cell separator, and will paste the contents into separate columns as shown below.


The Copy function enables us to very easily copy text to the clipboard and this post highlighted some practical examples of how to call this function.
  •   Categories: 
  • text