Im使用xlrd,xlwt,openpyxl进行excel文件操作 我有下面的方法,它检查文件夹中30多个文件,并更改文件中每一行的特定列(有些文件有5、15、17等行)
上面的方法可以反复运行,每个文件都会相应地更新。 但是, 一旦我编辑了文件(任何一个文件,编辑可以是其中一个单元格中的微小更改(例如从A更改为A),xlrd将无法读取该文件,我得到以下例外情况。 知道为什么吗?在
Exception:
Traceback (most recent call last):
File "/home/ohad/automationProj/automation-linux/0_master_code_prep.py", line 154, in
sanity_run_all_change()
File "/home/ohad/automationProj/automation-linux/0_master_code_prep.py", line 68, in sanity_run_all_change
ExcelWorkBook1 = open_workbook(config.STDFOLDER + '%s.xlsx'%suitename, on_demand=True)
File "/usr/local/lib/python2.7/dist-packages/xlrd/init.py", line 422, in open_workbook
ragged_rows=ragged_rows,
File "/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py", line 794, in open_workbook_2007_xml
x12sheet.process_stream(zflo, heading)
File "/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py", line 534, in own_process_stream
self.do_dimension(elem)
File "/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py", line 568, in do_dimension
rowx, colx = cell_name_to_rowx_colx(last_cell_ref)
File "/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py", line 91, in cell_name_to_rowx_colx
assert 0 <= colx < X12_MAX_COLS
AssertionError
代码:
def fullregression_run_all_change():
# FUll regression suites go over and change testes to Run
print "Go over Sanity suites and Change all Test to Run position"
ExcelWorkBook1 = open_workbook(config.UI_Suites_Location + 'STD_SUITES.xlsx', on_demand=True)
First_Sheet1 = ExcelWorkBook1.sheet_by_index(0)
Suite_List = []
for suitename in First_Sheet1._cell_values:
if suitename[1] == "Nightly Full Regression Run":
continue
else:
Suite_List.append(str(suitename[1]))
print "Full regression suites count is %s"%Suite_List.__len__()
for suitename in Suite_List:
ExcelWorkBook1 = open_workbook(config.STDFOLDER + '%s.xlsx'%suitename, on_demand=True)
First_Sheet1 = ExcelWorkBook1.sheet_by_index(0)
numberofrows=First_Sheet1.nrows
Startupdaterow=4
dest = config.STDFOLDER + suitename + ".xlsx"
wb = load_workbook(filename=dest)
ws = wb.get_active_sheet()
while Startupdaterow<=numberofrows:
ws.cell(row=Startupdaterow,column=8).value = 'RUN'
Startupdaterow +=1
wb.save(dest)
我的错误是
在Python的
.xls
文件中。在请访问此链接以查看我的答案,并在
sheet.py
中对MAX-COLUMNS
进行更改。在AssertionError with pandas when reading excel
我想你的问题会解决的。。。:)
相关问题 更多 >
编程相关推荐