Attempt to overwrite cell: sheetname=‘Sheet1‘ rowx=1 colx=0问题解决

Attempt to overwrite cell: sheetname=‘Sheet1’ rowx=1 colx=0问题解决

运行下边代码出现Attempt to overwrite cell: sheetname=‘Sheet1’ rowx=1 colx=0问题

for ws in wb.sheets():
    col0=ws.col_values(0)[1:]
    col1=ws.col_values(1)[1:]
    l=[[x,y] for x,y in zip(col0,col1)]
    # print(l)
    n=0
    for i in l:
        # print(ws.name,i[0],i[1])
        n+=1
        nws.write(n,0,ws.name)
        nws.write(n,1,i[0])
        nws.write(n,2,i[1])

添加断点查找到

    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)
            prev_cell_obj = self.__cells[col_index]
            sst_idx = getattr(prev_cell_obj, 'sst_idx', None)

在row.py中提示的错误 创建单元格重复,搜索到https://blog.csdn.net/u011636207/article/details/98102682
提供的解决办法是添加cell_overwrite_ok=True 程序可以继续运行但是把部分单元格跳过,于是返回查看代码,n=0赋予初值的位置在循环内部,导致重复创建单元格,将n=0移到循环的外部解决问题。

你可能感兴趣的:(python)