Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

migrated from math.stackexchange.com Mar 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). –  David Skulsky Mar 24 '12 at 4:29
1  
@David, I think = in the original question is important in relation to the "weird stuff about population counts...` OP is puzzled about. –  kguler Mar 24 '12 at 4:52
1  
@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. –  kguler Mar 24 '12 at 7:04
add comment

2 Answers 2

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.

share|improve this answer
5  
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
add comment

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:

enter image description here

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

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.