# Importing from Excel

I'm trying to import a matrix from Excel to Mathematica. My code is:

Import["desktop/stproj.xls", "xls", data, 1]


The output is some weird stuff about population counts and not at all related to what's in the excel file. Can anyone help me with importing this?

-

## migrated from math.stackexchange.comMar 24 '12 at 4:11

This question came from our site for people studying math at any level and professionals in related fields.

Marty Cohen's answer below is sage advice--I do the same when I'm trying to import data from a spreadsheet. If that's not an option, then you should probably make your spreadsheet accessible to the SE community. One thing I'll mention is that your import command should start with a capital letter (as do all built-in Mathematica functions). – Cassini Mar 24 '12 at 4:29
@David, I think = in the original question is important in relation to the "weird stuff about population counts... OP is puzzled about. – kglr Mar 24 '12 at 4:52
@R.M my comment about the previous edit was unintentionally directed to the David Skulsky. It was intended for David, but I could not figure out how to ping David. I think editing out = in the original version destroys the whole question. – kglr Mar 24 '12 at 7:04

With syntax errors fixed:

  Import[" appropriate path /Desktop/stproj.xls", "xls", "Data", 1]


should import the file.

Regarding population counts you are getting, the = sign at the beginning of an input cell invokes Wolfram Alpha query which allows free-form input (hence you get no syntax error warnings). Interestingly, Wolfram Alpha interprets the query somehow and returns:

If you click the red +` button on the top right to get the full results, you see why W|A returns with this result:

-

Whenever I want to import Excel data, I first save the Excel file as a csv file with either commas or tabs as the separators. The result is a pure text file that can be readily imported and manipulated.

-
Mathematica imports both .xls and .xlsx files so this is not necessary. – Verbeia Mar 24 '12 at 6:25
Importing from a csv file is faster than other formats in general. – sebastian c. Jan 9 '13 at 17:11