import pyXLWriter, StringIO
workbook = pyXLWriter.Workbook(StringIO.StringIO())
try:
sheet = workbook.add_worksheet()
for i in range(200):
try:
sheet.write_string((i,0), u'a')
except:
print '---- %d ----' % i
raise
finally:
workbook.close()
# As long as what written is unicode-string, the code
# always error at #row = 129
Logged In: YES
user_id=952405
Format of Excel 95 is not supported unicode. I will make stub,
only... sorry.
Logged In: YES
user_id=1186774
The fix is simple for me (unicode starings do not contain
non-ascii characters). Here is Worksheet.write_string method.
I do not know how to fix if someone really needs unicode.
def write_string(self, cell, _str, format=None):
"""Write a string to the specified row and column
(zero indexed).
NOTE: there is an Excel 5 defined limit of 255
characters.
format is optional.
Returns 0 : normal termination
-1 : insufficient number of arguments
-2 : row or column out of range
-3 : long string truncated to 255 chars
row - zero indexed row
col - zero indexed column
"""
_str = str(_str)
row, col = self._process_cell(cell)
record = 0x0204 # Record identifier
length = 0x0008 + len(_str) # Bytes to follow
strlen = len(_str)
xf = self._XF(row, col, format) # The cell format
str_error = 0
# Check that row and col are valid and store max and
min values
if self._check_dimensions(row, col):
#raise Exception("row and col not valid")
return -2
if (strlen > self._xls_strmax): # LABEL must be <
255 chars
_str = _str[0:self._xls_strmax]
length = 0x0008 + self._xls_strmax
strlen = self._xls_strmax
str_error = -3
header = pack("<HH", record, length)
data = pack("<HHHH", row, col, xf, strlen)
self._append(header, data, _str)
return str_error