Projet

Général

Profil

0001-correctly-export-numbers-to-ODS-fixes-28058.patch

Benjamin Dauvergne, 15 novembre 2018 16:35

Télécharger (2,4 ko)

Voir les différences:

Subject: [PATCH] correctly export numbers to ODS (fixes #28058)

 bijoe/visualization/ods.py   | 14 +++++++++++++-
 bijoe/visualization/utils.py |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)
bijoe/visualization/ods.py
16 16
# You should have received a copy of the GNU Affero General Public License
17 17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 18

  
19
import sys
20

  
19 21
import zipfile
20 22
import xml.etree.ElementTree as ET
21 23

  
......
25 27
XLINK_NS = 'http://www.w3.org/1999/xlink'
26 28

  
27 29

  
30
def is_number(x):
31
    if sys.version_info >= (3, 0):
32
        return isinstance(x, (int, float))
33
    else:
34
        return isinstance(x, (int, long, float))
35

  
36

  
28 37
class Workbook(object):
29 38
    def __init__(self, encoding='utf-8'):
30 39
        self.sheets = []
......
94 103

  
95 104
class WorkCell(object):
96 105
    def __init__(self, worksheet, value, hint=None):
106
        self.value_type = 'string'
107
        if is_number(value):
108
            self.value_type = 'float'
97 109
        if value is None:
98 110
            value = ''
99 111
        if type(value) is not unicode:
......
104 116

  
105 117
    def get_node(self):
106 118
        root = ET.Element('{%s}table-cell' % TABLE_NS)
107
        root.attrib['{%s}value-type' % OFFICE_NS] = 'string'
119
        root.attrib['{%s}value-type' % OFFICE_NS] = self.value_type
108 120
        p = ET.SubElement(root, '{%s}p' % TEXT_NS)
109 121
        if self.hint == 'uri':
110 122
            base_filename = self.value.split('/')[-1]
bijoe/visualization/utils.py
253 253
            sheet.write(0, 0, full_title)
254 254
            for j, row in enumerate(table.table()):
255 255
                for i, value in enumerate(row):
256
                    sheet.write(j + 1, i, unicode(0 if value is None else value))
256
                    sheet.write(j + 1, i, 0 if value is None else value)
257 257
        return workbook
258 258

  
259 259
    def title(self):
260
-