[BangPypers] "Error :Attempt to overwrite cell" while using xlwt to create excel sheets

nikunj badjatya nikunjbadjatya at gmail.com
Wed Feb 10 12:47:42 CET 2010

I am using xlwt 0.7.2 and Python 2.6.
I come across a situation wherein one of the "rows" of the excel sheet
created was being overwritten. And it was flagging the following

File "/usr/local/lib/python2.6/site-packages/xlwt/Row.py", line 150,
in insert_cell
     raise Exception(msg)
Exception: Attempt to overwrite cell

*Action Taken:*
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. ??* As in if I use my program on different system,
then again I have to comment out that line in row.py..!!
Any suggestions??
Bangalore, India

More information about the BangPypers mailing list