Function Repository Resource:

CopyAsExcelData

Source Notebook

Copy a list to the clipboard in a format that can be pasted directly into a spreadsheet

Contributed by: Sjoerd Smit

ResourceFunction["CopyAsExcelData"][list]

copies list to the clipboard in plain-text (TSV) form so that it can be pasted into Excel and most other spreadsheet and creates an output that can be clicked to copy the data again.

ResourceFunction["CopyAsExcelData"][str, "PlainText"]

copies String str to the clipboard as plain-text and generates a click-to-copy object for that string.

Details

ResourceFunction["CopyAsExcelData"] will copy the input data to the clipboard and also generate a click-to-copy object that makes it easy to copy the data again at a later moment.
The copied string is in Tab-Separated-Value (TSV) format.
ResourceFunction["CopyAsExcelData"][list] attempts to clean up elements in list such as DateObjects by converting them to strings. It then uses ExportString[, "Table"] to convert the result to plain-text.
ResourceFunction["CopyAsExcelData"] only accepts lists that can be interpreted as 2D arrays.
First[ResourceFunction["CopyAsExcelData"][list]] can be used to extract the String that was copied.

Examples

Basic Examples (2) 

Copy an array of random numbers:

In[1]:=
SeedRandom[1];
ResourceFunction["CopyAsExcelData"][RandomInteger[10, {5, 10}]]
Out[2]=

Go into Excel or any other spreadsheet application and paste the values:

Click the output to copy the data again at a later moment:


Flat lists and ragged arrays also work:

In[3]:=
ResourceFunction["CopyAsExcelData"][Range[10]]
Out[3]=
In[4]:=
ResourceFunction["CopyAsExcelData"][Range /@ Range[5]]
Out[4]=

Scope (3) 

Any element that is not a number or a string will be converted to a String:

In[5]:=
ResourceFunction[
 "CopyAsExcelData"][{1, "Hello", Now, Today, TimeObject[], Quantity[1, "USDollars"]}]
Out[5]=

Create a click-to-copy object for any plain-text string:

In[6]:=
ResourceFunction["CopyAsExcelData"]["Hello\tworld", "PlainText"]
Out[6]=

Note the difference with the normal ClickToCopy function, which will copy a Wolfram String instead:

In[7]:=
ClickToCopy["Hello\tworld"]
Out[7]=

Use First to retrieve the string that was copied to the clipboard:

In[8]:=
First @ ResourceFunction[
  "CopyAsExcelData"][{1, "Hello", Now, Today, TimeObject[], Quantity[1, "USDollars"]}]
Out[8]=

Properties & Relations (1) 

ExportString and CopyToClipboard can also be used to copy the data programmatically:

In[9]:=
SeedRandom[1];
data = RandomInteger[10, {5, 10}]
Out[10]=
In[11]:=
CopyToClipboard[ExportString[data, "TSV"]]

Publisher

Sjoerd Smit

Version History

  • 2.0.0 – 29 July 2022
  • 1.0.0 – 19 July 2022

Related Resources

License Information