From 3c5f646546a059bcd7860b181e4bc9452a2f7423 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 19 Aug 2015 22:45:23 +0100 Subject: [PATCH] =?UTF-8?q?fix=20#2:=20it=20turns=20out=20that=20string=20?= =?UTF-8?q?and=20unicode=20do=20not=20need=20value=20field=20in=20the=20ce?= =?UTF-8?q?ll.=20hence=20getting=20rid=20of=20it=20helps=20solve=20unicode?= =?UTF-8?q?=20encode=20error.=20it=20tried=20to=20do=20this=20and=20failed?= =?UTF-8?q?=20table:table-cell=20office:value-type=3Dunicode=20office:stri?= =?UTF-8?q?ng=3D'H=C3=A9ll=C3=B4'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyexcel_ods/__init__.py | 5 +++-- tests/test_bug_fixes.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pyexcel_ods/__init__.py b/pyexcel_ods/__init__.py index 22faad6..79800d2 100644 --- a/pyexcel_ods/__init__.py +++ b/pyexcel_ods/__init__.py @@ -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) @@ -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" diff --git a/tests/test_bug_fixes.py b/tests/test_bug_fixes.py index 1ae7357..a1e3949 100644 --- a/tests/test_bug_fixes.py +++ b/tests/test_bug_fixes.py @@ -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!']] \ No newline at end of file