Skip to content

Commit

Permalink
format web links and numbers as such in excel download. Format based …
Browse files Browse the repository at this point in the history
…on actual data, not field settings.
  • Loading branch information
tmog committed Feb 26, 2016
1 parent c86a891 commit d8a03a2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Products/PloneFormGen/content/saveDataAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
except ImportError:
has_xls = False

from urlparse import urlparse

from AccessControl import ClassSecurityInfo

from BTrees.IOBTree import IOBTree
Expand Down Expand Up @@ -466,6 +468,17 @@ def download_xls(self, REQUEST=None, RESPONSE=None):
for col_num, col in enumerate(row):
if type(col) is unicode:
col = col.encode(self.getCharset())

if urlparse(col).scheme in ('http', 'https'):
col = xlwt.Formula('HYPERLINK("%(url)s")' % dict(url=col))
else:
for format in (int, float):
try:
col = format(col)
break
except ValueError:
pass

sheet.write(row_num, col_num, col)
row_num += 1

Expand Down

0 comments on commit d8a03a2

Please sign in to comment.