Hi there,
I'm a newbie to Python, but have to use it because it is implemented as scripting language
in Codesys V3.5.
Therefore first many thanks to all the guys who are working or worked on this package,
it`s biliant and easy.
I'm working with CPython/GTK and IronPhyton on WinXP or Win7.
That are two Python's to run one at the scripting language and the other on win-systems
without Codesys, to use one code for both systems.
Now I have got 1 problem:
If I parse an Excel-file with CPython everything seems OK.
But if I parse an Excel-file with IronPython the type of the cells makes problems.
Like you can see in the description below the print output of the CPython gives me
the right type "unicode".
But the print output of the IronPython gives me the wrong type "str". But the encoding
seems to work because I can see the right chars of my german language.
PS:
I have fixed some issues I found while I tried to find out why that output of
IronPython does not fit or tracebacks comes up.
Feel free to use this informations.
Any suggestions or experience?
Versions:
############################
xlrd 0.9.2
Python 2.7.5
IronPython 2.7.3 (2.7.0.40)
Excel file ( Excel2010 saved as 2003 ):
############################
Sheet: ELCADExport
Data of columns A to B and row 1 to 6
Test,Michael
1.0,äöü
2.0,ß
3.0,µ
4.0,?
5.0,HALLO
made following changes:
#######################
xlrd\compdoc.py ( nearby row 330 ):
###########
if todo != 0:
fprintf(self.logfile,
"WARNING *** OLE2 stream %r: expected size %d, actual size %d\n",
name, size, size - todo)
# Michael
# changed the return line to let this module work in IronPython 2.7
# I think .join makes different results in .net
# old line at row 335 =
# return b''.join(sectors)
# my solution:
f = b''
for i in range(0,len(sectors)):
f = f + sectors[i]
return f
def _dir_search(self, path, storage_DID=0):
xlrd\__init__.py ( nearby row 323 ):
( didn`t change anything of the output !!!!!!!!! )
###########
from .xldate import XLDateError, xldate_as_tuple
# Michael
# changed the import of encodings work in IronPython 2.7
# sys.version starts not with IronPython it starts with Versioninformations
# old line at row 325 =
# if sys.version.startswith("IronPython"):
# my solution:
if "IronPython" in sys.version:
# print >> sys.stderr, "...importing encodings"
import encodings
try:
xlrd\book.py ( nearby row 15 ):
( didn`t change anything of the output !!!!!!!!! )
###########
from . import formatting
# Michael
# changed the import of encodings work in IronPython 2.7
# sys.version starts not with IronPython it starts with Versioninformations
# old line at row 16 =
# if sys.version.startswith("IronPython"):
# my solution:
if "IronPython" in sys.version:
# print >> sys.stderr, "...importing encodings"
import encodings
empty_cell = sheet.empty_cell # for exposure to the world ...
Outputs of both Pythons:
############################
CPython:
############################
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win
32
>>> import sys
>>> sys.path.insert(0, r'Z:\Daten\Uebungen_Michael\Uebungen Pygtk2\UtilityExcel\
UtilitiesExcel\UtilitiesExcel\resources\Excel')
>>> from xlrd import open_workbook
>>> wb = open_workbook( filename = r'C:\Temp\test.xls' )
>>> encoding = wb.encoding
>>> print ( encoding )
utf_16_le
>>> for s in wb.sheets():
... if type(
s.name) == 'unicode':
... print 'Sheet:',s.name.encode(encoding )
... else:
... for row in range(s.nrows):#(s.nrows): (0,120):
... values = []
... for col in range(s.ncols):
... values.append(s.cell(row,col).value)
... print values
... print type(values[0])
... if type(values[0]) == 'unicode':
... print values[0].encode(encoding )
... else:
... print values[0]
... print type(values[1])
... if type(values[1]) == 'unicode':
... print values[1].encode(encoding )
... else:
... print values[1]
...
<type 'unicode'>
Sheet: ELCADExport
[u'Test', u'Michael']
<type 'unicode'>
Test
<type 'unicode'>
Michael
[1.0, u'\xe4\xf6\xfc']
<type 'float'>
1.0
<type 'unicode'>
äöü
[2.0, u'\xdf']
<type 'float'>
2.0
<type 'unicode'>
ß
[3.0, u'\xb5']
<type 'float'>
3.0
<type 'unicode'>
µ
[4.0, u'?']
<type 'float'>
4.0
<type 'unicode'>
?
[5.0, u'HALLO']
<type 'float'>
5.0
<type 'unicode'>
HALLO
>>>
IronPython:
############################
IronPython 2.7.3 (2.7.0.40) on .NET 4.0.30319.1 (32-bit)
>>> import sys
>>> sys.path.insert(0, r'Z:\Daten\Uebungen_Michael\Uebungen Pygtk2\UtilityExcel\
UtilitiesExcel\UtilitiesExcel\resources\Excel')
>>> from xlrd import open_workbook
>>> wb = open_workbook( filename = r'C:\Temp\test.xls' )
>>> encoding = wb.encoding
>>> print ( encoding )
utf_16_le
>>> for s in wb.sheets():
... if type(
s.name) == 'unicode':
... print 'Sheet:',s.name.encode(encoding )
... else:
... for row in range(s.nrows):#(s.nrows): (0,120):
... values = []
... for col in range(s.ncols):
... values.append(s.cell(row,col).value)
... print values
... print type(values[0])
... if type(values[0]) == 'unicode':
... print values[0].encode(encoding )
... else:
... print values[0]
... print type(values[1])
... if type(values[1]) == 'unicode':
... print values[1].encode(encoding )
... else:
... print values[1]
...
<type 'str'>
Sheet: ELCADExport
['Test', 'Michael']
<type 'str'>
Test
<type 'str'>
Michael
[1.0, u'\xe4\xf6\xfc']
<type 'float'>
1.0
<type 'str'>
äöü
[2.0, u'\xdf']
<type 'float'>
2.0
<type 'str'>
ß
[3.0, u'\xb5']
<type 'float'>
3.0
<type 'str'>
µ
[4.0, '?']
<type 'float'>
4.0
<type 'str'>
?
[5.0, 'HALLO']
<type 'float'>
5.0
<type 'str'>
HALLO
>>>