No I can't seem to get it to work! I tried two tests.
import pyXLWriter as xl
import time
import datetime
workbook = xl.Writer("simple555.xls")
worksheet = workbook.add_worksheet()
def evalBoole(s):
if s in ('True', 'False'):
return eval(s)
else:
raise ValueError
def evalDateStr(s):
# return a struct_time object given a string representation
# changed it to day month year
return time.strptime(s, '%d/%m/%Y')
def convertType(s):
for func in (int, float, evalBoole, evalDateStr):
try:
n = func(s)
return n
except:
pass
return s
#changed to read in file line by line
print "\nLooping through the file, line by line."
f = open("omg.txt", "r")
for i, line in enumerate(f):
for j, obj in enumerate([convertType(item) for item in
[w.strip() for w in line.strip().split('\t')]
]):
#print 'Row %d, Column %d, Value: %s' % (i,j,obj)
worksheet.write([i, j], datetime.date(2008,02,01))
f.close()
workbook.close()
That
works when you explicitly give it a value, either date, string or intger/float
But it
doesn't work when I do
import pyXLWriter as xl
import time
import datetime
workbook = xl.Writer("simple555.xls")
worksheet = workbook.add_worksheet()
def evalDateStr(s):
# return a struct_time object given a string representation
# changed it to day month year
return time.strptime(s, '%d/%m/%Y')
def convertType(s):
for func in (int, float, evalDateStr):
try:
n = func(s)
return n
except:
pass
return s
#changed to read in file line by line
print "\nLooping through the file, line by line."
f = open("omg.txt", "r")
for i, line in enumerate(f):
for j, obj in enumerate([convertType(item) for item in
[w.strip() for w in line.strip().split('\t')]
]):
#print 'Row %d, Column %d, Value: %s' % (i,j,obj)
worksheet.write([i, j], obj)
f.close()
workbook.close() it fails, it doesn't even write to excel file!!!!
Do I need to create a function such as:
if obj = str then
s = str(obj)
worksheet.write ([i,j], s)
else if obj = integer then
i = int(obj)
worksheet.write([i,j], i)
else if obj = date then
a = split date by commas =day
b = split date by commas = month
c = split date by commas = year
worksheet.write([i,j], datetime.date(c,b,a))
end
If so how do I do this. I don't know anything about python!!!! THanks I'm almost finished.