xlrd Excel in python

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 7537 Views - Last Post: 10 July 2012 - 10:29 PM Rate Topic: -----

#1 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

xlrd Excel in python

Posted 18 May 2012 - 03:17 PM

How do I open a .xls file with python? I use Windows

My goal is to read each column of the spreadsheet and save it in a vector. It's possible?
Is This A Good Question/Topic? 0
  • +

Replies To: xlrd Excel in python

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: xlrd Excel in python

Posted 18 May 2012 - 04:06 PM

I usually don't post "Just Google it" responses, but seriously, you could have found multiple valid ansvers to this question by just putting it in a search engine.

The most promising answers on that first Google page (to my non-Python developer eyes) are:
- Read Excel files from Python
- Working with Excel files in Python (PDF)


If you've already tried some of those methods and failed to make it work, say so. Show us what didn't work, and perhaps we may be able to help you fix it.
Was This Post Helpful? 1
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: xlrd Excel in python

Posted 18 May 2012 - 04:21 PM

Yeah, I probably would have posted a lmgtfy link as I did with this post earlier this week :)
Was This Post Helpful? 1
  • +
  • -

#4 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

Re: xlrd Excel in python

Posted 18 May 2012 - 04:32 PM

View PostAtli, on 18 May 2012 - 04:06 PM, said:

I usually don't post "Just Google it" responses, but seriously, you could have found multiple valid ansvers to this question by just putting it in a search engine.

The most promising answers on that first Google page (to my non-Python developer eyes) are:
- Read Excel files from Python
- Working with Excel files in Python (PDF)


If you've already tried some of those methods and failed to make it work, say so. Show us what didn't work, and perhaps we may be able to help you fix it.


I've searched on the internet but do not have the module xlrd for windows and trying to open direct with open() does not work
Was This Post Helpful? 0
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: xlrd Excel in python

Posted 18 May 2012 - 04:36 PM

So, you need to download files for reading and writing to excel? Did you try using the googles?

This post has been edited by atraub: 18 May 2012 - 04:54 PM
Reason for edit:: you left me no choice

Was This Post Helpful? 0
  • +
  • -

#6 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

Re: xlrd Excel in python

Posted 18 May 2012 - 04:55 PM

View Postatraub, on 18 May 2012 - 04:36 PM, said:

So, you need to download files for reading and writing to excel? Did you try using the googles?


I'm sorry, I'm sleeping.
I found xlrd1 for windows
I tried a program to print the cell A1
import xlrd1

wb = xlrd1.open_workbook('file.xls')

sh = wb.sheet_by_index(0)

print sh.cell(0,0).value




Output:
Traceback (most recent call last):
  File "file.py", line 3, in <module>
    wb = xlrd1.open_workbook('file.xls')
  File "C:\Python27\xlrd1\__init__.py", line 431, in open_workbook
    on_demand=on_demand,
  File "C:\Python27\xlrd1\__init__.py", line 899, in biff2_8_load
    f = open(filename, open_mode)
IOError: [Errno 22] invalid mode ('rb') or filename: 'file.xls'



What am I doing wrong?
Was This Post Helpful? 0
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: xlrd Excel in python

Posted 18 May 2012 - 05:00 PM

Are you sure file.xls is in the same directory as the script you're running?
Was This Post Helpful? 0
  • +
  • -

#8 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

Re: xlrd Excel in python

Posted 18 May 2012 - 05:13 PM

View Postatraub, on 18 May 2012 - 05:00 PM, said:

Are you sure file.xls is in the same directory as the script you're running?


Yes. I've also tried specifying the path

I used \\ and work. But now gave the following error

raise XLRDError('Unsupported format, or corrupt file: ' + msg)
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found 'ABCD\t'


Was This Post Helpful? 0
  • +
  • -

#9 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: xlrd Excel in python

Posted 18 May 2012 - 05:18 PM

it says your file format is bad, are you sure that it's a valid xls file?
Was This Post Helpful? 0
  • +
  • -

#10 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

Re: xlrd Excel in python

Posted 18 May 2012 - 05:32 PM

View Postatraub, on 18 May 2012 - 05:18 PM, said:

it says your file format is bad, are you sure that it's a valid xls file?


Yes is a xls with more than 2GB. I tried to read the cell A1 to test. My goal is to store each column in a vector
Was This Post Helpful? 0
  • +
  • -

#11 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

Re: xlrd Excel in python

Posted 18 May 2012 - 05:54 PM

The problem is that my Excel file have more rows than allowed. As I have split this file into smaller pieces?
Was This Post Helpful? 1
  • +
  • -

#12 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: xlrd Excel in python

Posted 18 May 2012 - 07:23 PM

I dunno, that could be it. Give it a try and let us know what happens.
Was This Post Helpful? 0
  • +
  • -

#13 crazy123  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 138
  • Joined: 04-August 11

Re: xlrd Excel in python

Posted 18 May 2012 - 07:45 PM

View Postatraub, on 18 May 2012 - 07:23 PM, said:

I dunno, that could be it. Give it a try and let us know what happens.


I do not know how to divide a file .xls
If the reports that Excel can not open all the lines which program can?
Was This Post Helpful? 0
  • +
  • -

#14 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: xlrd Excel in python

Posted 18 May 2012 - 08:12 PM

Probably a .net language would be better suited for this.
Was This Post Helpful? 0
  • +
  • -

#15 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: xlrd Excel in python

Posted 19 May 2012 - 09:11 AM

View Postcrazy123, on 18 May 2012 - 10:45 PM, said:

View Postatraub, on 18 May 2012 - 07:23 PM, said:

I dunno, that could be it. Give it a try and let us know what happens.


I do not know how to divide a file .xls
If the reports that Excel can not open all the lines which program can?


To divide an xls, simply take a certain amount of the file, push ctrl-x, open another file and push ctrl-v.
You will want to divide it by rows and not by columns.
Was This Post Helpful? 2
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3