Skip to content

Commit

Permalink
Merge pull request #108 from OpenDataServices/421-remove-control-char
Browse files Browse the repository at this point in the history
[#421] remove control char
  • Loading branch information
Bjwebb authored Jun 13, 2016
2 parents 7b2f4d4 + be583bc commit d0f14e6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion flattentool/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
"""

import openpyxl
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
import csv
import os
import sys
from warnings import warn
import six

if sys.version > '3':
import csv
Expand Down Expand Up @@ -52,7 +55,16 @@ def write_sheet(self, sheet_name, sheet):
worksheet.title = sheet_name
worksheet.append(sheet_header)
for sheet_line in sheet.lines:
worksheet.append([ sheet_line.get(x) for x in sheet_header ])
line = []
for header in sheet_header:
value = sheet_line.get(header)
if isinstance(value, six.text_type):
new_value = ILLEGAL_CHARACTERS_RE.sub('', value)
if new_value != value:
warn("Character(s) in '{}' are not allowed in a spreadsheet cell. Those character(s) will be removed".format(value))
value = new_value
line.append(value)
worksheet.append(line)

def close(self):
self.workbook.remove_sheet(self.workbook.active)
Expand Down

0 comments on commit d0f14e6

Please sign in to comment.