I'm guessing we can't see your code?
If not, can you distil it down to as small an amount of python which
reproduces the issue?
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
Are you *creating* any styles?
>
> I'm guessing we can't see your code?
I'm guessing that your tracebacks are also state secrets :-(
> If not, can you distil it down to as small an amount of python which
> reproduces the issue?
Essentially, you must be using Worksheet.write(row_index, column_index,
data_value, xf_aka_style) ... what is xf_aka_style, how do you create
it/them, is creation done once or is it done within your worksheet /
row_index / column_index loops?
What version of xlwt are you using?
Can "largish" be expressed numerically?
You "occasionally" get that error after how many worksheets / rows /
columns? Have you noticed anything that may be correlated with getinng
the error or not getting it?
...and we have a winner.
Create the style *once* in your outermost part of the function and
re-used it, rather than creating a new style each and every time you
write a date cell...
[snip]
> Here's the code:
>
> def generate_excel(filename, col_title_list, data_row_list):
> import StringIO
> output = StringIO.StringIO()
Nothing to do with your problem, but: consider using cStringIO
> export_wb = Workbook()
> export_sheet = export_wb.add_sheet('Export')
> col_idx = 0
> for col_title in col_title_list:
> export_sheet.write(0, col_idx, col_title)
> col_idx += 1
Nothing to do with your problem, but: consider using enumerate e.g.
instead of the above 4 lines, do this. Ditto with your iteration over
rows and columns later.
for col_idx, col_title in enumerate(col_title_list):
export_sheet.write(0, col_idx, col_title)
> row_idx = 1
> for row_item_list in data_row_list:
> col_idx = 0
> for current_value in row_item_list:
> if not current_value == None:
> current_value_is_date = False
Nothing to do with your problem, but: why are you mucking about with
xlrd.xldate.xldate_from_*_tuple ...
> if isinstance(current_value, datetime.datetime):
> current_value =
> xlrd.xldate.xldate_from_datetime_tuple((current_value.year,
> current_value.month, \
> current_value.day,
> current_value.hour, current_value.minute, \
>
> current_value.second), 0)
> current_value_is_date = True
> elif isinstance(current_value, datetime.date):
> current_value =
> xlrd.xldate.xldate_from_date_tuple((current_value.year,
> current_value.month, \
>
> current_value.day), 0)
> current_value_is_date = True
> elif isinstance(current_value, datetime.time):
> current_value =
> xlrd.xldate.xldate_from_time_tuple((current_value.hour,
> current_value.minute, \
>
> current_value.second))
> current_value_is_date = True
... instead of replacing all of that by:
if isinstance(current_value, (datetime.datetime, datetime.date,
datetime.time)):
current_value_is_date = True
?
> elif isinstance(current_value, models.Model):
> current_value = str(current_value)
> if current_value_is_date:
> s = XFStyle()
> s.num_format_str = 'M/D/YY'
Everything to do with your problem: you are creating a new style for
each date etc value in your data. Don't do that. Create the style ONCE
at the start of the function. Give it a meaningful name. Hint: "s" is
not a meaningful name.
> export_sheet.write(row_idx, col_idx,
> current_value, s)
> else:
> export_sheet.write(row_idx, col_idx,
> cleanup_cell_value(current_value))
> col_idx += 1
> row_idx += 1
> export_wb.save(output)
> output.seek(0)
> return output
>
>
> The data_row_list is a python list of items representing each row.
> Each item in the list is a list of values, one per column. The other
> parameters are self-explanatory...
>
> xlwt version is 0.7.2.
>
> I appreciate any insight anyone can offer..
[snip]
>> Essentially, you must be using Worksheet.write(row_index, column_index,
>> data_value, xf_aka_style) ... what is xf_aka_style, how do you create
>> it/them, is creation done once or is it done within your worksheet /
>> row_index / column_index loops?
The above can't be construed as insight?