CopyPasteTools

Simple copy and paste between Mathematica and Excel, and other applications.

ver 1.0 June 30, 2003

Ken Kikuchi 
kikuchi@neti.com

({{CopyAsPlainText }, {PasteAsPlainText }, {\(\({}\)\(\ \)\(⇒\)\(\ \)\(Excel\)\(\ \)\)}, {\(\({}\)\(\ \)\(⇐\)\(\ \)\(Excel\)\(\ \)\)}, {List⇒Excel }})

Description

CopyPasteTools  is an add-on palette that provides a simple copying and pasting data between Mathematica and other applications such as Microsoft Excel. The palette contains five buttons that helps you move data back and forth with specified format. The file (CopyPasteTools.nb) is the palette, and additional documentation is provided in (AboutCopyPasteTools.nb). 
({{CopyAsPlainText }}) button gives you copy the text on Mathematica to other applications in plain text format. 
({{PasteAsPlainText }}) button gives you paste the text on Mathematica without style information.
({{\(\({}\)\(\ \)\(⇒\)\(\ \)\(Excel\)\(\ \)\)}}) CopyToExcel button gives you copy the contents in List format (eg. {{a,b},{c,d}} on Mathematica to tab-delimited table on Excel.
({{\(\({}\)\(\ \)\(⇐\)\(\ \)\(Excel\)\(\ \)\)}}) PasteFromExcel button gives you paste the contents in List format on Mathematica from cells copied on Excel.
To see more details at the Palette Interface section.

Installation

To download the necessary files

You need to retrieve two files from this directory:
	AboutCopyPasteTools.nb (this file)
	CopyPasteTools.nb

To install on your system

For once only testing

Open (or double click) the CopyPasteTools.nb at any location. Please read though the Usage section in this document.

For automatic placement when opening Mathematica

1) Place the downloaded CopyPasteTools.nb file into the following directory.
\Mathematica 4.x Files\Configuration\FrontEnd\Palette
or
\Mathematica 4.x Files\SystemFiles\FrontEnd\Palette

2) Start Mathematica, open the palette through menu File/Palette.

Palette Interface

({{CopyAsPlainText }})

Feature

Makes a copy of a selected characters and places them on the clipboard in plain-text format. It simply calls "Copy As Plain Text" in the Edit menu.

Usage

1) Select the contents on Mathematica, press CopyAsPlainText button on the  CopyPasteTools  palette.
2) Switch to other application such as mailer software, select a destination or an insertion point, and paste the contents.

Example

1) Select the following styled-format text, press CopyAsText button.

This is a sample of Styled Text.

2) Specify insertion point at anywhere on Mathematica, execute the ordinal paste (eg., Ctrl+V or Cmd+V). You will see the following in plain-text format.

This is a sample of Styled Text.

Note

1) If you copy the Input cell, the label In[ ]:= will be copied.
2) If you copy graphics such as Plot result, the postscript code will be copied.

({{PasteAsPlainText }})

Feature

Places the contents of the clipboard at the insertion point in plain-text format. It calls "Paste As Plain Text" in the Edit menu.

Usage

1) Open an application such as Microsoft Word. Copy the contents you want to copy in plain-text format.

2) Switch to Mathematica, select a destination or an insertion point, press PasteAsPlainText button on the  CopyPasteTools  palette

Example

1) Select the following styled-format text, then make ordinal copy such as Ctrl+C or Cmd+C.

This is a sample of Styled Text.

2) Specify insertion point anywhere on Mathematica, press PasteAsPlainText button on the  CopyPasteTools  palette. You will see the following in plain-text format.

This is a sample of Styled Text.

Note

N/A

({{\(\({\ }\)\(\ \)\(⇒\)\(\ \)\(Excel\)\(\ \)\)}}) CopyToExcel

Feature

Makes a copy of a data set in List ({...}) format and place them on the clipboard in tab-delimited table. Functionally, it may call CopyAsTabDelimitedText.

Usage

1) Select the contents in List {{...}) format on Mathematica, press CopyToExcel button on the  CopyPasteTools  palette.
2) Switch to Excel (or other application), select a destination or an insertion point, and paste the contents.

Example

Select the following data, press "CopyToExcel" button on the  CopyPasteTools  palette.

{{aa,bb},{cc,dd}}

Switch to Excel, select a destination cell, and paste. You will see the following.

({{    ,  A , B, C}, {1, aa              , bb               ,        }, {2, cc               , dd              ,         }, {3,  ,  ,  }})

Or, if you paste on Mathematica, you will see the following tab-delimited text.

aa	bb
cc	dd

Note

1) More than two dimensions (example below) will be converted in two dimensions.

{{{x,y,z},111},{yyy,222}}

Excel will show the following when you execute CopyToExcel for the above.

({{      , A, B, C, D}, {1, x             , y             , z             ,          111}, {2, yyy         ,         222,  ,  }, {3,  ,  ,  ,  }})

Or, if you paste the contents on Mathematica, you will see the following as tab-separated text.

x	y	z	111
yyy	222

2) CopyToExcel does not work for data if wrapped by MatrixForm or TableForm. Please convert them in List format by InputForm prior to use CopyToExcel.

({{\(\({\ }\)\(\ \)\(⇐\)\(\ \)\(Excel\)\(\ \)\)}}) PasteFromExcel

Feature

Places the contents of the clipboard at the insertion point in List ({}) format after the conversion from tab-delimited text on the clipboard. Functionally it may call PasteFromCommaDelimitedText.

Usage

1) Open Microsoft Excel or other application. Copy cells (or any tab-delimited text) you want to duplicate in List ({}) format on Mathematica.
2) Switch to Mathematica, select a destination or an insertion point, press PasteFromExcel button on the  CopyPasteTools  palette

Example

Open Excel and select the cells, copy them on Excel. The screen image is the following.

({{    ,  A , B, C}, {1, aaa              ,             111,        }, {2, bbb              ,             222,         }, {3,  ,  ,  }})

Switch to Mathematica, select a destination or an insertion point, press PasteFromExcel button on the  CopyPasteTools  palette. You will see the following List formatted contents.

{{aaa,111},{bbb,222}}

({{List⇒Excel }}) CopyListToExcel

Feature

Makes a copy of a data set with the following List command (instead of List {} format) and place them on the clipboard in tab-delimited table.
List[ List[ a, b], List[ c, d] ]

Usage

1) Select the contents written by List command (instead of List {} format) on Mathematica, press CopyListToExcel button on the  CopyPasteTools  palette.
2) Switch to Excel (or other application) and paste.

Example

Select the following contents, press CopyListToExcel button on the  CopyPasteTools  palette.

List[List[xxx, 111], List[yyy, 222]]

Switch to Excel, select a destination cell, and paste. You will see the following.

({{    ,  A , B, C}, {1, xxx              ,              111,          }, {2, yyy               ,              222,           }, {3,  ,  ,  }})

Or, if you paste the contents on Mathematica, you will see the following tab-delimited text.

xxx	111
yyy	222

Note

More than two dimensions list (example below) will be converted in two dimensions.

List[List[List[x,y,z], 111], List[yyy, 222]]

Excel will show the following for the above list.

({{      , A, B, C, D}, {1, x             , y             , z             ,          111}, {2, yyy         ,         222,  ,  }, {3,  ,  ,  ,  }})

Or, if you paste within Mathematica, you will see the following.

x	y	z	111
yyy	222

Notes

1) Implementation of error checking are minimum. Copy of unexpected data or unexpected data format will cause of unexpected result.
2) All features were tested on Mathematica 4.2 for Macintosh with Microsoft Excel for Macintosh 8.0 (a.k.a. Office 98) on Mac OS X 10.2.6.
3) The unexpected beep sound with no-selection error (on the ClipboardNotebook), or the lack of memory error (when move contents to the clipboard from ClipboardNotebook) are under investigation. I some difficulty for workaround with Developer`ClipboardNotebook on 4.2.

I am very pleased to have your suggestions.
Ken Kikuchi