Skip to content

Commit

Permalink
Substituting characters disallowed in XML when exporting to Excel2007…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
Nick Pellegrino committed Oct 8, 2013
1 parent c0bd0c7 commit e3ef1cb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion couchexport/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ def _init_table(self, table_index, table_title):

def _write_row(self, sheet_index, row):
sheet = self.tables[sheet_index]
# Source: http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
dirty_chars = re.compile(
u'[\x00-\x08\x0b-\x1f\x7f-\x84\x86-\x9f\ud800-\udfff\ufdd0-\ufddf\ufffe-\uffff]')
# NOTE: don't touch this. changing anything like formatting in the
# row by referencing the cells will cause huge memory issues.
# see: http://packages.python.org/openpyxl/optimized.html
sheet.append([unicode(v) for v in self.get_data(row)])
sheet.append([dirty_chars.sub(unicode('?'), unicode(v)) for v in self.get_data(row)])

def _close(self):
"""
Expand Down

0 comments on commit e3ef1cb

Please sign in to comment.