Skip to content

Commit

Permalink
Replaced vendored openpyxl by a dependency
Browse files Browse the repository at this point in the history
Thanks Tommy Anthony for the initial patch.
  • Loading branch information
claudep committed Aug 30, 2016
1 parent 0cf5495 commit cdbb78f
Show file tree
Hide file tree
Showing 68 changed files with 26 additions and 11,310 deletions.
13 changes: 5 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,19 @@
'tablib.packages.xlwt',
'tablib.packages.xlrd',
'tablib.packages.odf',
'tablib.packages.openpyxl',
'tablib.packages.openpyxl.shared',
'tablib.packages.openpyxl.reader',
'tablib.packages.openpyxl.writer',
'tablib.packages.yaml',
'tablib.packages.dbfpy',
'tablib.packages.xlwt3',
'tablib.packages.xlrd3',
'tablib.packages.odf3',
'tablib.packages.openpyxl3',
'tablib.packages.openpyxl3.shared',
'tablib.packages.openpyxl3.reader',
'tablib.packages.openpyxl3.writer',
'tablib.packages.yaml3',
'tablib.packages.dbfpy3'
]

install = [
'openpyxl',
]


setup(
name='tablib',
Expand All @@ -90,5 +86,6 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
),
install_requires = install,
tests_require=['pytest'],
)
2 changes: 0 additions & 2 deletions tablib/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import tablib.packages.xlrd3 as xlrd
from tablib.packages.xlrd3.biffh import XLRDError
from tablib.packages import markup3 as markup
from tablib.packages import openpyxl3 as openpyxl
from tablib.packages.odf3 import opendocument, style, text, table
import tablib.packages.dbfpy3 as dbfpy

Expand All @@ -48,7 +47,6 @@
from tablib.packages.xlrd.biffh import XLRDError
from tablib.packages import markup
from itertools import ifilter
from tablib.packages import openpyxl
from tablib.packages.odf import opendocument, style, text, table

from tablib.packages import unicodecsv as csv
Expand Down
35 changes: 16 additions & 19 deletions tablib/formats/_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
else:
from cStringIO import StringIO as BytesIO

from tablib.compat import openpyxl
import openpyxl
import tablib

Workbook = openpyxl.workbook.Workbook
Expand Down Expand Up @@ -51,7 +51,8 @@ def export_book(databook, freeze_panes=True):
"""Returns XLSX representation of DataBook."""

wb = Workbook()
wb.worksheets = []
for sheet in wb.worksheets:
wb.remove_sheet(sheet)
for i, dset in enumerate(databook._datasets):
ws = wb.create_sheet()
ws.title = dset.title if dset.title else 'Sheet%s' % (i)
Expand Down Expand Up @@ -111,42 +112,38 @@ def dset_sheet(dataset, ws, freeze_panes=True):
_offset = i
_package.insert((sep[0] + _offset), (sep[1],))

bold = openpyxl.styles.Font(bold=True)
wrap_text = openpyxl.styles.Alignment(wrap_text=True)

for i, row in enumerate(_package):
row_number = i + 1
for j, col in enumerate(row):
col_idx = get_column_letter(j + 1)
cell = ws.cell('%s%s' % (col_idx, row_number))

# bold headers
if (row_number == 1) and dataset.headers:
# ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
# '%s' % col, errors='ignore')
ws.cell('%s%s'%(col_idx, row_number)).value = unicode(col)
style = ws.get_style('%s%s' % (col_idx, row_number))
style.font.bold = True
# cell.value = unicode('%s' % col, errors='ignore')
cell.value = unicode(col)
cell.font = bold
if freeze_panes:
# As already done in #53, but after Merge lost:
# Export Freeze only after first Line
ws.freeze_panes = 'A2'

# bold separators
elif len(row) < dataset.width:
ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
'%s' % col, errors='ignore')
style = ws.get_style('%s%s' % (col_idx, row_number))
style.font.bold = True
cell.value = unicode('%s' % col, errors='ignore')
cell.font = bold

# wrap the rest
else:
try:
if '\n' in col:
ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
'%s' % col, errors='ignore')
style = ws.get_style('%s%s' % (col_idx, row_number))
style.alignment.wrap_text
cell.value = unicode('%s' % col, errors='ignore')
cell.alignment = wrap_text
else:
ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
'%s' % col, errors='ignore')
cell.value = unicode('%s' % col, errors='ignore')
except TypeError:
ws.cell('%s%s'%(col_idx, row_number)).value = unicode(col)
cell.value = unicode(col)


53 changes: 0 additions & 53 deletions tablib/packages/openpyxl/__init__.py

This file was deleted.

Loading

0 comments on commit cdbb78f

Please sign in to comment.