[BangPypers] [Tutor] "Error :Attempt to overwrite cell" while using xlwt to create excel sheets
kent37 at tds.net
Wed Feb 10 13:43:25 CET 2010
On Wed, Feb 10, 2010 at 6:47 AM, nikunj badjatya
<nikunjbadjatya at gmail.com> wrote:
> I commented out the "raise Exception" statement in Row.py library
> Here's the (line no. 150 ) of Row.py which i have edited:
> def insert_cell(self, col_index, cell_obj):
> if col_index in self.__cells:
> if not self.__parent._cell_overwrite_ok:
> msg = "Attempt to overwrite cell: sheetname=%r rowx=%d
> colx=%d" \
> % (self.__parent.name, self.__idx, col_index)
> #raise Exception(msg)
> #########*commented to avoid error.
> prev_cell_obj = self.__cells[col_index]
> sst_idx = getattr(prev_cell_obj, 'sst_idx', None)
> if sst_idx is not None:
> self.__cells[col_index] = cell_obj
> The excel sheet creation code now works fine.
> My question is, Instead of manually goin to /usr/lib/.../row.py and
> commenting out the line, Can this be done through few lines of code in
> my program itself. ??
Looking at the code above, you can see that the exception is raised
only if self.__parent._cell_overwrite_ok is False. So there is an
option to allow overwriting.
>From the error message it appears that self.__parent is a Worksheet.
Looking at the source code for Worksheet.py, the __init__() method
does have an optional cell_overwrite_ok= parameter. This parameter is
also available in Workbook.add_sheet(). So if you pass
cell_overwrite=True to add_sheet() you should be OK.
More information about the BangPypers