MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Copying from Excel 97


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11272] Re: Copying from Excel 97
  • From: "P.J. Hinton" <paulh@wolfram.com>
  • Date: Wed, 4 Mar 1998 01:39:27 -0500
  • Organization: Wolfram Research, Inc.
  • References: <6dg7nl$2sa@smc.vnet.net>

On 3 Mar 1998, Lawrence Walker wrote:

> When I try copying a block of values from Excel 97 to Mathematica3 I get
> a list of numbers with the first entry of each row running together
> with the last number from the previous row.  As a result I have to
> manually enter spaces between the numbers.
> 
> For instance, given the following block of numbers in Excel (each in
> different cells):
> 
>     1    2   3
>     4    5   6
>     7    8   9
> 
> If I copied the block and paste it into Mathematica then I would get...
> 
> 1 2 34 5 67 8 9
> 
> After which I would have to edit the entry with separators.
> 
> {1, 2, 3,4, 5, 6,7, 8, 9}
> 
> For this case it was easy, but for large blocks of number this gets
> somewhat confusing.
> How do I prevent Mathematica or Excel from forcing numbers to run
> together?

If you're working with large blocks of numbers, it is probably better to
use a text file rather than the system clipboard as your transfer
medium.

Excel, like many other spread sheet programs, should have an option for
saving the cells of a worksheet as a plain text file of space or tab
delimited data.  For the sake of simplicity, avoid saving the contents
as comma delimited data.  You may want to check the documentation with
Excel for exact steps on how to do this. 

To import the information into Mathematica as a list, simply invoke the
ReadList command: 

	ReadList[<filename>, Number, RecordLists -> True]

Where <filename> refers to a string with the name (possibly with path)
of the export you created earlier.  RecordLists tells the kernel to
store each record in the file as a separate sublist, so if your file
looks like

1 	3 	5
7 	9 	11

Mathematica will read this in as 

	{{1,3,5},{7,9,11}}

You can use the front end menu commnad Input -> Get File Path... to
browse for this export file.  When you select the file, the filename
with path will be pasted as a string wherever your text cursor is
located in the Mathematica notebook. 

--
P.J. Hinton
Mathematica Programming Group           paulh@wolfram.com Wolfram
Research, Inc.                  http://www.wolfram.com/~paulh/
Disclaimer: Opinions expressed herein are those of the author alone.




  • Prev by Date: ListPlot3D Color
  • Next by Date: Re: Plotting
  • Prev by thread: Re: Copying from Excel 97
  • Next by thread: Re: Compiling