blob: 3698726f9846b285cfde06900301cb5dd3168bbd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# -*- coding: utf-8 -*-
""" Tablib - XLS Support.
"""
import xlwt
import cStringIO
title = 'xls'
extentions = ('xls',)
wrap = xlwt.easyxf("alignment: wrap on")
def export_set(dataset):
"""Returns XLS representation of Dataset."""
wb = xlwt.Workbook(encoding='utf8')
ws = wb.add_sheet(dataset.title if dataset.title else 'Tabbed Dataset')
for i, row in enumerate(dataset._package(dicts=False)):
for j, col in enumerate(row):
ws.write(i, j, col, wrap)
stream = cStringIO.StringIO()
wb.save(stream)
return stream.getvalue()
def export_book(databook):
"""Returns XLS representation of DataBook."""
wb = xlwt.Workbook(encoding='utf8')
for i, dset in enumerate(databook._datasets):
ws = wb.add_sheet(dset.title if dset.title else 'Sheet%s' % (i))
#for row in self._package(dicts=False):
for i, row in enumerate(dset._package(dicts=False)):
for j, col in enumerate(row):
ws.write(i, j, col, wrap)
stream = cStringIO.StringIO()
wb.save(stream)
return stream.getvalue()
|