Reading from excel file, printing to text file.

1,384 views
Skip to first unread message

stad

unread,
Aug 4, 2009, 5:41:19 AM8/4/09
to python-excel
Hello!

I`m kinda new to python and I started a project.The program should
work like this: it reads an excel file, counts the number of columns
that are in the file, selects two specific columns (the number of the
columns are inserted from the keyboard) and prints those two columns
to a .txt file. All this it`s gonna be packed nice with easyGUI.

I took an eye on http://www.python-excel.org/ and "Working with Excel
file in Python" and I got a basic idea about the xlrd and all the rest
of the packages. My question... It is possible to do the program using
those packages and the tutorial? (as I said I didn`t studied the
tutorial, I only read it through the lines).

Thanks,
Danci Emanuel

Chris Withers

unread,
Aug 4, 2009, 5:43:08 AM8/4/09
to python...@googlegroups.com
stad wrote:
> I took an eye on http://www.python-excel.org/ and "Working with Excel
> file in Python" and I got a basic idea about the xlrd and all the rest
> of the packages. My question... It is possible to do the program using
> those packages and the tutorial?

Yes.

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

stad

unread,
Aug 4, 2009, 5:44:01 AM8/4/09
to python-excel


On Aug 4, 12:43 pm, Chris Withers <ch...@simplistix.co.uk> wrote:
> stad wrote:
> > I took an eye onhttp://www.python-excel.org/and "Working with Excel
> > file in Python" and I got a basic idea about the xlrd and all the rest
> > of the packages. My question... It is possible to do the program using
> > those packages and the tutorial?
>
> Yes.
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             -http://www.simplistix.co.uk

May I ask how difficult that would be?

Chris Withers

unread,
Aug 4, 2009, 5:55:19 AM8/4/09
to python...@googlegroups.com
stad wrote:
>
> May I ask how difficult that would be?

Not very. I'd suggest reading the tutorial on python-excel.org.

cheers,

stad

unread,
Aug 4, 2009, 6:59:02 AM8/4/09
to python-excel

I have another problem. When I try to install xlrd it appears a weird
error message : "Could not set key value". I use Windows 7 & Python
3.1. How can I fix that?

Wouter van Heyst

unread,
Aug 4, 2009, 7:57:01 AM8/4/09
to python...@googlegroups.com

What exactly gives that error? Is there a traceback?

Wouter van Heyst

Chris Withers

unread,
Aug 4, 2009, 8:33:49 AM8/4/09
to python...@googlegroups.com

You need to give us the full traceback from the error.

That said, I doubt xlrd works with Python 3 yet, I suggest you try again
with Python 2.6.

cyrull

unread,
Aug 5, 2009, 5:34:32 AM8/5/09
to python-excel
First of all, I'm using xlrd with python 2.5. I know it works with
2.6, I'm not sure with latter version.
Second : I suggest you to go here : http://code.activestate.com/recipes/483742/
You'll find a complete class that can be use to read Excel files with
xlrd. So now, you just have to works on your GUI !


On 4 Aug, 11:41, stad <danci.eman...@gmail.com> wrote:
> Hello!
>
> I`m kinda new to python and I started a project.The program should
> work like this: it reads an excel file, counts the number of columns
> that are in the file, selects two specific columns (the number of the
> columns are inserted from the keyboard) and prints those two columns
> to a .txt file. All this it`s gonna be packed nice with easyGUI.
>
> I took an eye onhttp://www.python-excel.org/and "Working with Excel

stad

unread,
Aug 5, 2009, 6:12:48 AM8/5/09
to python-excel


The xlrd does not work with python 3.1. That was the problem. I
installed the 2.6 version and it`s working. Thanks for your priceless
help!

John Machin

unread,
Aug 5, 2009, 6:44:39 AM8/5/09
to python...@googlegroups.com
On 5/08/2009 7:34 PM, cyrull wrote:
> First of all, I'm using xlrd with python 2.5. I know it works with
> 2.6, I'm not sure with latter version.
> Second : I suggest you to go here : http://code.activestate.com/recipes/483742/
> You'll find a complete class that can be use to read Excel files with
> xlrd.

Did you read the comments on that recipe? Any reason for not preferring
the sanitised version at http://gizmojo.org/code/readexcel/ ?

cyrull

unread,
Aug 5, 2009, 8:42:39 AM8/5/09
to python-excel
no reason, it was just the first I founded and the one I'm using.
I never suggest something that I don't have tested, but it seems to be
better with your own version.

stad

unread,
Aug 5, 2009, 9:38:47 AM8/5/09
to python-excel
How can I check if a sheet is empty?

Chris Withers

unread,
Aug 5, 2009, 11:11:49 AM8/5/09
to python...@googlegroups.com
stad wrote:
> How can I check if a sheet is empty?

You need to start by deciding what you mean by "empty"...

John Machin

unread,
Aug 5, 2009, 11:43:46 AM8/5/09
to python...@googlegroups.com
On 5/08/2009 10:42 PM, cyrull wrote:
> no reason, it was just the first I founded and the one I'm using.

So you're using the crappy one instead of the better one for no reason?

> I never suggest something that I don't have tested, but it seems to be
> better with your own version.

What seems to be better than what with whose own version of what????

John Machin

unread,
Aug 5, 2009, 11:49:58 AM8/5/09
to python...@googlegroups.com
On 5/08/2009 11:38 PM, stad wrote:
> How can I check if a sheet is empty?

sheet.nrows or sheet.ncols would be a good start.

stad

unread,
Aug 5, 2009, 12:37:14 PM8/5/09
to python-excel



sheet.nrows or sheet.ncols would be a good start.

Thank you!

stad

unread,
Aug 5, 2009, 3:09:20 PM8/5/09
to python-excel
How can I convert hour format into string or any format in order to
print it using the xlrd.

The file has one column that is the hour (06:15, 06:30, etc) and this
column has to appear int the .txt file.

txtFile is the file in which I the program writes the data from the
excel file.

I tried this - txtFile.write(s.cell(row,col).value) - but I get an
error.

With the other values (floats, etc) I used - txtFile.write(' ' +
str(s.cell(row,col).value)).

How can I solve the problem?

stad

unread,
Aug 5, 2009, 3:29:51 PM8/5/09
to python-excel

It reads this:
06:15
06:30
06:45
07:00
07:15
07:30
07:45

and it`s printing this:
0.260416666667
0.270833333333
0.28125
0.291666666667
0.302083333333
0.3125

Chris Withers

unread,
Aug 5, 2009, 4:09:05 PM8/5/09
to python...@googlegroups.com
stad wrote:
> How can I convert hour format into string or any format in order to
> print it using the xlrd.
>
> The file has one column that is the hour (06:15, 06:30, etc) and this
> column has to appear int the .txt file.

Why don't you rtfm, specifically the big section about dates and times?

cyrull

unread,
Aug 6, 2009, 3:34:40 AM8/6/09
to python-excel


On 5 Aug, 17:43, John Machin <sjmac...@lexicon.net> wrote:
> On 5/08/2009 10:42 PM, cyrull wrote:
>
> > no reason, it was just the first I founded and the one I'm using.
>
> So you're using the crappy one instead of the better one for no reason?

I work with the "crappy" version for a long time and probably before
the creation of the "probably better" one. And I never had any trouble
with my version. That's all.
So, there is a reason for me to work with the "crappy" version and no
reason to prefer it to the "probably better" one.
I'll try the better version next week and I'll see if I can make the
change.
But, because I never have used the "probably better" version, I won't
suggest it to anybody.

stad

unread,
Aug 11, 2009, 9:07:37 AM8/11/09
to python-excel

I finished the project. Thank you all for you help!

ahmed....@gmail.com

unread,
Mar 7, 2014, 8:15:21 AM3/7/14
to python...@googlegroups.com


On Tuesday, August 11, 2009 2:07:37 PM UTC+1, stad wrote:

I finished the project. Thank you all for you help!


hello... i have a similar project. can i have a look at what you did. thanks
Reply all
Reply to author
Forward
0 new messages