wcs.xlwt.diff
wcs/backoffice/root.ptl (copie de travail) | ||
---|---|---|
39 | 39 |
from wcs.forms.backoffice import FormDefUI |
40 | 40 | |
41 | 41 |
try: |
42 |
import pyExcelerator
|
|
42 |
import xlwt
|
|
43 | 43 |
except ImportError: |
44 |
pyExcelerator = None
|
|
44 |
xlwt = None
|
|
45 | 45 | |
46 | 46 |
def format_time(t, units = 2): |
47 | 47 |
days = int(t/86400) |
... | ... | |
243 | 243 |
'<ul>' |
244 | 244 |
'<li><a href="listing">%s</a></li>' % _('Listing') |
245 | 245 |
'<li><a href="csv">%s</a></li>' % _('Listing in CSV format') |
246 |
if pyExcelerator:
|
|
246 |
if xlwt:
|
|
247 | 247 |
'<li><a href="xls">%s</a></li>' % _('Listing in Excel format') |
248 | 248 |
'<li><a href="pending">%s</a></li>' % _('Pending Forms') |
249 | 249 |
'<li><a href="stats">%s</a></li>' % _('Statistics') |
... | ... | |
342 | 342 |
return output.getvalue() |
343 | 343 | |
344 | 344 |
def xls(self): |
345 |
if pyExcelerator is None:
|
|
345 |
if xlwt is None:
|
|
346 | 346 |
raise errors.TraversalError() |
347 | 347 | |
348 | 348 |
get_logger().info('backoffice - form %s - as excel' % self.formdef.name) |
349 | 349 | |
350 | 350 |
fields = FormDefUI(self.formdef).get_listing_fields() |
351 | 351 | |
352 |
w = pyExcelerator.Workbook() |
|
353 |
pyExcelerator.UnicodeUtils.DEFAULT_ENCODING = 'iso-8859-15' |
|
352 |
w = xlwt.Workbook(encoding='utf-8') |
|
354 | 353 |
ws = w.add_sheet('1') |
355 | 354 | |
356 | 355 |
for i, f in enumerate(self.csv_tuple_heading(fields)): |
... | ... | |
361 | 360 |
for j, elem in enumerate(self.csv_tuple(fields, filled)): |
362 | 361 |
ws.write(i+1, j, elem) |
363 | 362 | |
363 |
output = cStringIO.StringIO() |
|
364 |
w.save(output) |
|
365 | ||
364 | 366 |
response = get_response() |
365 | 367 |
response.set_content_type('application/vnd.ms-excel') |
366 | 368 |
response.set_header('content-disposition', 'attachment; filename=export.xls') |
367 |
return w.get_biff_data()
|
|
369 |
return output.getvalue()
|
|
368 | 370 | |
369 | 371 |
def stats [html] (self): |
370 | 372 |
get_logger().info('backoffice - form %s - stats' % self.formdef.name) |