views:

284

answers:

2

hi, how do i insert few row in an existing excel file using python? the excel file maybe be of any excel version. On windows that could have been possible by using win32com.client...but i need to make the changes in the linux environment. how can i do it?

+1  A: 

http://www.saltycrane.com/blog/2010/02/using-python-write-excel-openoffice-calc-spreadsheet-ubuntu-linux/

thats all you need

TheSteve0
hi,is there some way where in i can directly insert the data into the exisiting sheet? the way you suggested helps, but then it will involve copying a existing sheet and then creating a new one to have my data included in it.
crystal
I am not sure - I usually use Java and POI. When I download the library and look at the source files the workbook object has a get_sheet method which returns a worksheet in the workbook. You can probably do all the insertions you want with that worksheet.
TheSteve0
@TheSteve0: Don't believe everything that you read in a blog; "here is how to write Excel or OpenOffice.org Calc spreadsheet files using Python and the xlwt library" ... write OpenOffice.org Calc spreadsheet files with xlwt??? News to me.
John Machin
@crystal: That's exactly what happens when a user opens a file with Excel [loads contents into memory], adds some more data [in memory], and saves it [REMOVE OLD FILE, write new file from memory]. An Excel file has a complicated structure; it's a much bigger deal than appending a bunch of fixed-size blocks to an exiisting file.
John Machin
Hey John - I was just focusing on Crystal using it for excel - not the OO use.
TheSteve0
+2  A: 

you can use pyExcelerator. the package comes with example demos to write excel files

ghostdog74
xlwt is a fork of pyExcelerator so the demos are probably the same. Based on this http://groups.google.com/group/python-excel/browse_thread/thread/ea65395fc7856beeI would say that pyExcelerator is no longer maintained
TheSteve0
@ghostdog74: pyExcelerator has a bad case of the Norwegian Blue Parrot syndrome. xlwt has extra functionality, better speed, uses less memory and has a tutorial ... see http://www.python-excel.org
John Machin
thanks. I used pyExcelerator long ago.
ghostdog74