15
$\begingroup$

Is there a simple way to copy/paste a table of data from Mathematica into Excel? I know I can Export the data, but copy/paste would be so much more convenient for a variety of reasons.

I've tried copy/paste from InputForm, from TableForm, using Print to format the output ... but nothing works.

$\endgroup$

5 Answers 5

18
$\begingroup$

surprisingly simple.. use TableForm or MatrixForm

 {{1, 2}, {3, 4}} // TableForm

Then select the data, right-click, "copy as" "plain text" and paste into an excel cell.

If you have a MatrixForm be sure to select only the data, not the brackets.

$\endgroup$
2
  • $\begingroup$ This works well and easy to remember, so I mark it "correct". Others should make note that Sjoerd's answer is great, too, but a bit harder to remember IMO. $\endgroup$
    – GregH
    Commented Apr 4, 2018 at 12:38
  • 1
    $\begingroup$ If keyboard shortcuts are your thing, you can also do Copy As Plain Text with Control-Shift-C or Command-Shift-C. $\endgroup$ Commented Apr 4, 2018 at 12:46
23
$\begingroup$

I usually do something like:

ExportString[myTable,"TSV"]//CopyToClipboard

with the table in the variable myTable.

$\endgroup$
2
  • $\begingroup$ This is so slick - love it. I ended up marking another correct as it is easier to remember. $\endgroup$
    – GregH
    Commented Apr 4, 2018 at 12:39
  • 2
    $\begingroup$ @GregH Glad you like it. If remembering this is an issue you could always use a user defined function with a better name instead and put it in an init.m file. The additional advantage of the method is that it also works on huge tables that you don’t want to have on your screen. $\endgroup$ Commented Apr 4, 2018 at 12:48
3
$\begingroup$

Nothing beats ExcelLink for interacting with Excel. I even figured out how to load Excel files that exceeded the Java Virtual Heap size limit using ExcelLink (Importing a large Excel file). That problem may have gone away in 11.3, but it shows kind of things you can do with it. Of course, you do have to buy ExcelLink, but I couldn't live without it.

I have to admit that Sjoerd's trick is neat.

$\endgroup$
1
$\begingroup$

I simply use the Export function, e.g.

Export["data.csv", Table[Table[i*j, {i,10}], {j,10}]]

and then open the temporary output file in Excel and copy its data. Not the best solution I know, but does the job...

$\endgroup$
1
$\begingroup$

For those that want to avoid mouse clicks at the expense of possibly more keypresses, postfixing //TableForm//TextCell//CopyToClipboard can be a quick fix as well:

 {{1, 2}, {3, 4}, {5,6}} //TableForm//TextCell//CopyToClipboard

This avoids the need of selecting the output, right-clicking, and choosing "Copy As" > "Plain Text".

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.