get integer from textfile and write to excel with python
Question: I already get the value from text file and write it to excel file. But somehow
in the excel cell the integer written in string. So there's a green triangle
in the cell. Like this ![This is the output of the
file](http://i.stack.imgur.com/knVpn.png)

I want to print like this

![enter image description here](http://i.stack.imgur.com/qUKR4.png)

and this is the code

    
    
    from itertools import chain
    import glob ,csv, sys, os
    
    sys.path.insert(0,'D:/apera/Python27/xlwt-0.7.5')
    
    import xlwt
    
    openMesureFile = 'D:/apera/Workspace/Python scripting test 2/sounding0.txt'
    savePlace = 'D:/apera/Workspace/Sounding/sounding{0:03d}.txt'
    openSoundingFile = 'D:/apera/Workspace/Sounding/*.txt'
    
    with open(openMesureFile, 'rb') as inf:
        header = next(inf)
        for index, line in enumerate(inf,start=0):
            with open(savePlace.format(index) ,'w') as outf:
                outf.write('Filename:;%s\n\n' %outf.name)
    
                outf.write(header)
                for line in chain([line], inf):
                    if 'Sounding :;Sondage n°' in line:
                        header = line
                        break
                    outf.write(line)
    
    for filename in glob.glob(openSoundingFile):
        wb = xlwt.Workbook(encoding="latin1")
        sheet = wb.add_sheet('INPUT')
        newName = filename
        spamReader = csv.reader(open(filename, 'rb'), delimiter=';',quotechar='"')
        for rowx, row in enumerate(spamReader):
            for colx, value in enumerate(row):
                sheet.write(rowx, colx, value)
    
        sheet.col(0).width = 5555
        sheet.col(1).width = 11110
        sheet.col(2).width = 5555
        sheet.col(3).width = 3333
    
        wb.save(newName[:-4] + ".xls")
    
    print "success"
    


Answer: From the
[docs](https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/doc/xlwt.html?p=4966)

> write(r, c, label="", style=Style.default_style) [#]  
>  label The data value to be written. An int, long, or decimal.Decimal
> instance is converted to float.

Thus a `str` input will be taken as a `string` in excel. Thus you will have to
type cast it explicitly.

In your program this can be done from changing a single line:

from

    
    
     sheet.write(rowx, colx, value)
    

to

    
    
     sheet.write(rowx, colx, float(value))
    

