Open Office and Python

F

F

Hello there!

I'd like to load a .csv file to the Open Office spreadsheet from the command
line using an arbitrary delimiter through Python. I don't need any fancy
formatting and stuff like that, just putting the values in the spreadsheet
will do.

Is there a relatively simple way to do that?

Sorry for the unfocused nature of this question. I wouldn't have asked it if
this weren't a one-off task and if I didn't need this urgently.

Any help and pointers would be greatly appreciated.

Thanks and best regards,

F.
 
B

Ben Sizer

F said:
I'd like to load a .csv file to the Open Office spreadsheet from the command
line using an arbitrary delimiter through Python. I don't need any fancy
formatting and stuff like that, just putting the values in the spreadsheet
will do.

Is there a relatively simple way to do that?

I assume when you say load you mean create. To 'load' usually means to
read data rather than write it. If you want to read the data in, then a
Google search for "python csv" should answer all your questions.

Otherwise...

How are the values stored? It might be as simple as this:

# sample data
table = [
("item1", 10, 100),
("item 2", 15, 300)
]

out = file("my.csv", "w+")
for row in table:
out.write(",".join(str(item) for item in row) + "\n")

And my.csv will look like:
item1,10,100
item 2,15,300
 
T

tobiah

F said:
Hello there!

I'd like to load a .csv file to the Open Office spreadsheet from the command
line using an arbitrary delimiter through Python.

I put together a little utility that you may find helpful
if I understand you correctly. It converts a .csv file
to a .xls file without the need for the GUI. It makes a
good guess as to the appropriate column width for each
column. You could easily fix it to use any delimiter
as an argument. It's here:

http://tobiah.org/csv2xls

It needs PyExcellerator:

http://sourceforge.net/projects/pyexcelerator

Tobiah
 
T

tobiah

I should have pointed out that the delimiter is a tab
right now. That's what I use in general, but I still
call the files .csv files. Also this doesn't check
for, or handle quoted fields.
 
M

Marc 'BlackJack' Rintsch

I should have pointed out that the delimiter is a tab
right now. That's what I use in general, but I still
call the files .csv files. Also this doesn't check
for, or handle quoted fields.

Why don't you use the `csv` module from the standard library?

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top