[Tutor] saving .csv file as an xl worksheet
Hi, last week I had to make a simple solution to convert prn file to excel. It seems to be very similar. I just wondered how easy to create an xml file that can be opened with excel. It can have functions, autofilters, format descriptions. It is about 100 times faster to create than on the win32com way. It is twice bigger than the binary excel, but it can be compressed into the half size of the compressed binary. People working with excel can't feel the difference :) I don't know how can it be opened with StarOffice, but it works well with excel2003. ## import os xmlhead = """ http://www.w3.org/TR/REC-html40";> """ xmlsum = """ """ xmlfoot = """ """ headrow = ('1st;2nd;3rd') lines = ('1;2;3', '2;3;4', '3;4;5', '4;5;6') dest = 'Test.xls' xml = open(dest, 'wt') rownum = 1 ## Header xml.write(xmlhead) ## HeadRow xml.write('\n') for data in headrow.split(';'): xml.write(' %s\n' % data) xml.write('\n') rownum += 1 ## Rows with data for line in lines: colnum = len(line.split(';')) xml.write('\n') for data in line.split(';'): xml.write(' %s\n' % data) xml.write('\n') rownum += 1 ## Function with reference xml.write(xmlsum % (rownum-2)) ## Foot xml.write(xmlfoot % (rownum, colnum)) xml.close() os.execl(r'c:\Program Files\Microsoft Office\Office10\EXCEL.EXE', dest) ## Yours sincerely, __ János Juhász Date: Tue, 7 Mar 2006 16:38:46 +1100 From: andrew clarke <[EMAIL PROTECTED]> Subject: Re: [Tutor] saving .csv file as an xl worksheet To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=us-ascii On Mon, Mar 06, 2006 at 02:46:36PM +0530, arun wrote: > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. Just changing the file extension from .csv to .xls won't change the file format. OpenOffice 2.0 supports both .csv and .xls file formats and includes some sort of Python integration. It may be possible to use that. Regards Andrew ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving .csv file as an xl worksheet
On Mon, Mar 06, 2006 at 02:46:36PM +0530, arun wrote: > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. Just changing the file extension from .csv to .xls won't change the file format. OpenOffice 2.0 supports both .csv and .xls file formats and includes some sort of Python integration. It may be possible to use that. Regards Andrew ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving .csv file as an xl worksheet
arun wrote: > Hi , > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. It's easy to rename a file, or read it and save it with whatever name you like, but that won't convert it to an actual Excel worksheet. To write true xls files you can use win32com to control Excel through its COM interface (google python excel for many examples) or you can use pyExcelerator. http://cheeseshop.python.org/pypi/pyExcelerator/0.6.0a Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving .csv file as an xl worksheet
Hello, .xls is a proprietary format used by Microsoft office, and unless you have the specs for that format and are willing to implement them (very very hard) it would not make much sense. If you absolutely need that, then maybe a macro in VBA from Excel itself may be a better option. Changing the file extension only (just the filename, not the contents of the file) can be done using the shutil module in Python (high level file manipulation) Hugo arun wrote: > Hi , > Can i save a file with a desired extension?? > for ex: I have a .csv file (test.csv) and i want to save this file as > test.xls from a python script. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] saving .csv file as an xl worksheet
Hi , Can i save a file with a desired extension?? for ex: I have a .csv file (test.csv) and i want to save this file as test.xls from a python script. Thanx in advance ac ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor