0
첫 번째 열의 내용을 스크롤하고 각 고유 값을 새 통합 문서, 즉 중복되지 않는 것으로 작성하려는 Excel 통합 문서가 있습니다. 그러나리스트를 반복 할 때 파이썬 유니 코드 문제가 발생했습니다.
def get_data_from_sheet(sheet_index, start_row, end_row, count):
for row in range(start_row, end_row):
cell = sheet.cell(row,0)
count = count+1
if row != start_row:
sheet1.write(count,0,cell.value)
return count
을 내가 중복 확인하기 위해 조건을 추가 할 때, 아무것도 엑셀 파일에 기록되지 않은 :
이 코드는 중복 확인하지 않고, 잘 작동
from django.utils.encoding import smart_str
def get_data_from_sheet(sheet_index, start_row, end_row, count):
for row in range(start_row, end_row):
cell = sheet.cell(row,0)
count = count+1
if row != start_row:
list.append(smart_str(cell.value))
if smart_str(cell.value) not in list:
sheet1.write(count,0,cell.value)
return count
목록에 값이 포함되어 있기 때문에 어떤 퍼즐이 나옵니까? :
그래서 내가 뭘 잘못하고 있니? 감사! 그렇지 않은
if smart_str(cell.value) not in list:
당신이 목록에 값을 추가로 당신은, 테스트가 항상 False
될 것이라고 확신 단지 테스트하기 전에 :이 전에
list.append(smart_str(cell.value))
이를 호출하여
D' oh! 고마워. – user578582
@ user578582 또한'count'를 증가 시키면'if' 스위트 안에 있어야합니다. 그렇지 않으면 각 복사본이 원래 파일에있는 빈 행을 얻게됩니다. –