float converted to string in ods

Asked by Peter Veltman


I just started using POD. I have created an *.ods template and
managed to get a result.ods from the renderer, which fills desired

Now the problem is that the fields are filled with something like '2014
and not the number 2014. According to your website this should happen,
so could you point me to why this is going wrong?

I have a dataDict = { 'year': 2014 } and in the ods: ="year".

Kind Regards,


Question information

English Edit question
Appy Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
davide moro (davide-moro) said :

Hi Peter,
I experienced the same issue.

Have you found a workaround for this?

Best regards,


Revision history for this message
Peter Veltman (p-veltman) said :

Yes, I've created my own parser/generator.

## code ## (no further help)
import zipfile
import xml.dom.minidom

dataDict = {'$month':'oktober',
                     '$value': 9.0} ## or any other string that you've defined in the template

outfile = "output.ods"
## Read template
tempFile = zipfile.ZipFile('template.ods', mode='r')
tempFileList = tempFile.infolist()

## Create outputFile
outFile = zipfile.ZipFile(outfile, mode='w')
for tFile in tempFileList:
    if (tFile.orig_filename!='content.xml'):
        stringFile = tempFile.read(tFile.orig_filename)

## Now search and replace content in template and write this to outFile
contentFile = tempFile.read('content.xml')
doc = xml.dom.minidom.parseString(contentFile)
cells = doc.getElementsByTagName('table:table-cell')
#print "I have ", len(cells), "cells "
for cell in cells:
    cellData = ''
    for i in range(0,cell.attributes.length):
        ## Find the cells that are strings, check if the text:p element data is equal to a dict.key
            ##print cell.attributes.item(i).name,cell.attributes.item(i).value
            nodeList = cell.getElementsByTagName('text:p')
            for p in nodeList:
                for ch in p.childNodes:
                    if ch.nodeType == ch.TEXT_NODE:
                        ##print ch.data
                        cellData = ch.data
                        if cellData in dataDict.keys():
                            #print "before: ",cell.toxml()
                            #print cellData
                           ## next lines are not nice, I make a difference between string outputs and floats in the XML file
                           ## So I check here for the dict.keys() which don't have string values
                            if (cellData!='$month' and cellData!='$year'):
    #print "after: ",cell.toxml()
## Then write to content.xml.
newContentFile = doc.toxml().encode('utf-8')
print "Saved data to", outfile

Revision history for this message
davide moro (davide-moro) said :

Thank you for sharing!

Instead for who needs a solution without having to write their own parser here it is a non techical workaround:
* add a hidden cell with ="myfloatvar" (for example E7)
* put a formula on the cell you want to display with =VALUE(E7) if you need a float or =INT(E7) for integers

Revision history for this message
Launchpad Janitor (janitor) said :

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Gaƫtan Delannay (gaetan-delannay) said :

See the related bug.