Skip to content

Commit

Permalink
fix #2: it turns out that string and unicode do not need value field …
Browse files Browse the repository at this point in the history
…in the cell. hence getting rid of it helps solve unicode encode error. it tried to do this and failed table:table-cell office:value-type=unicode office:string='Héllô'
  • Loading branch information
chfw committed Aug 19, 2015
1 parent 663f7e4 commit 3c5f646
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pyexcel_ods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def write_cell(self, row, x):
converter = ODS_VALUE_CONVERTERS.get(x_odf_type, None)
if converter:
x = converter(x)
tc.setAttrNS(OFFICENS, x_odf_value_token, x)
if x_odf_type != 'string':
tc.setAttrNS(OFFICENS, x_odf_value_token, x)
tc.addElement(P(text=x))
row.addElement(tc)

Expand Down Expand Up @@ -302,4 +303,4 @@ def get_data(afile, file_type=None, **keywords):
return read_data(afile, file_type=file_type, **keywords)


__VERSION__ = "0.0.7"
__VERSION__ = "0.0.9"
11 changes: 10 additions & 1 deletion tests/test_bug_fixes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import os
from pyexcel_ods import get_data
from pyexcel_ods import get_data, save_data


def test_bug_fix_for_issue_1():
data = get_data(os.path.join("tests", "fixtures", "repeated.ods"))
assert data['Sheet1'] == [['repeated', 'repeated', 'repeated', 'repeated']]

def test_bug_fix_for_issue_2():
data = {}
data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
data.update({"Sheet 2": [[u"row 1", u"Héllô!", u"HolÁ!"]]})
save_data("your_file.ods", data)
new_data = get_data("your_file.ods")
assert new_data["Sheet 2"] == [[u'row 1', u'H\xe9ll\xf4!', u'Hol\xc1!']]

0 comments on commit 3c5f646

Please sign in to comment.