I'm generating an excel file using xlwt and store it on datastore as blob property. But during the generation got this error "Timeout: The datastore operation timed out, or the data was temporarily unavailable."
.
I have noticed that using xlutils we can update the exsisting files. I'm planning to do something like this, first time i will craete the file with half of my data and using another task will complete the file creation.
is there any better way to do this ?
Here is my current code:
from xlwt import *
wb = Workbook()
ws0 = wb.add_sheet("Sheet 1")
style = XFStyle()
style.font.name = 'Tahoma'
currency_style = XFStyle()
currency_style.num_format_str = '$#,##0.00'
ws0.write(0, 0, 'Col 1', style)
ws0.write(0, 1, 'Col 2', style)
ws0.write(0, 2, 'Col 3', style)
ws0.write(0, 3, 'Col 4', style)
rx = 1
for each in db_result:
ws0.write(rx, 0, each.col1, style)
ws0.write(rx, 1, each.col2, style)
ws0.write(rx, 2, each.col3, style)
try:
ws0.write(rx, 3, round(float(each.col4), 2), currency_style)
except:
ws0.write(rx, 3, each.col4, style)
rx = rx + 1
db.delete(each)
buffer = StringIO.StringIO()
wb.save(buffer)
contents = buffer.getvalue()
f = myfile()
f.name = 'File 1'
f.file = db.Blob(contents)
f.put()