import os, sys
from xlrd import open_workbook
from xlutils.copy import copy
from xlwt import easyxf, Style
import time
rb = open_workbook('A1.xls', on_demand=True,formatting_info =True)
rs = rb.sheet_by_index(0)
wb = copy(rb)
ws = wb.get_sheet(0)
start =time.time()
g1 = dict()
for row in range(1,rs.nrows):
for cell in row:
cellContent = str(cell.value)
if cellContent not in g1.keys():
g1[cellContent]=1
else:
g1[cellContent]=g1[cellContent]+1
for cellContent in g1.keys():
print cellContent, g1[cellContent]
ws.write(row,1, cellContent)
wb.save('A2.xls')
当我运行这段代码,我得到错误信息cell
对象不是可迭代 什么可能出了错?获取我的输出到另一个Excel文件
我已经重新设置了代码的格式,但显然它是python缩进级别的关键。请您确认缩进仍然正确。无论如何,我相信这是正确的,您的问题将会出现。 – Edd 2014-10-08 14:21:02
问题是与行:“对于行中的单元格:”与错误消息“整数对象是不可迭代的。” – Bethogee 2014-10-08 14:28:19