OK my xls to tab convertor is working now!
1.0
2.0 0
3.0
1 4.0
5.0
6.0
7.0
20-60-20083 02/05/2008
All I need to do is create a tab to xls convertor and I'll be done.
Underneath is code with writes to an excel file using the module pyXLWriter.
How do I change it so it reads in the tab file as above and change the values?
import pyXLWriter as xl
import datetime
# Create a new workbook called simple.xls and add a worksheet
workbook = xl.Writer("simple.xls")
worksheet = workbook.add_worksheet()
# The general syntax is write(row, column, token). Note that row and
# column are zero indexed
# Write some text
#worksheet.write([0, 0], "Hi Excel!")
# Write some numbers
worksheet.write([2, 0], 3) # Writes 3
worksheet.write([3, 6], 3.00000) # Writes 3
worksheet.write([4, 0], datetime.date(2004,04,15)) #write date 15/04/2004
worksheet.write([5, 0], "hi") # Write string
# Write some formulas
#worksheet.write([7, 0], '=A3 + A6')
#worksheet.write([8, 0], '=IF(A5>3,"Yes", "No")')
# Write a hyperlink
#worksheet.write([10, 0], 'http://www.perl.com/')
workbook.close()
I did try using
#!/usr/bin/env python
# This example script was ported from Perl Spreadsheet::WriteExcel module.
# The author of the Spreadsheet::WriteExcel module is John McNamara
# <jmcnamara@cpan.org>
__revision__ = """$Id: tab2xls.py,v 1.1 2004/01/31 18:57:53 fufff Exp $"""
######################################################################
#
# Example of how to use the WriteExcel module
#
# The following converts a tab separated file into an Excel file
#
# Usage: tab2xls.pl tabfile.txt newfile.xls
#
# reverse('(c)'), March 2001, John McNamara, jmcnamara@cpan.org
#
import sys
import pyXLWriter as xl
# Check for valid number of arguments
if len(sys.argv) != 3:
print "Usage: tab2xls tabfile.txt newfile.xls"
sys.exit(1)
else:
tabfilename, xlsfilename = sys.argv[1:3]
# Open the tab delimited file
tabfile = file(tabfilename, "r")
# Create a new Excel workbook
workbook = xl.Writer(xlsfilename)
worksheet = workbook.add_worksheet()
# Row and column are zero indexed
nrow = 0
for line in tabfile.xreadlines():
# Split on single tab
row = line.split('\t')
for ncol, cell in enumerate(row):
worksheet.write([nrow, ncol], cell.strip())
nrow += 1
tabfile.close()
workbook.close()
And that does write to excel but it doesn't recognise dates as being dates and numbers being numbers so it is more or less useless.