【问题标题】:Python -xlrd library - assert 0 <= colx < X12_MAX_COLS-AssertionErrorPython -xlrd 库 - 断言 0 <= colx < X12_MAX_COLS-AssertionError
【发布时间】:2018-04-28 09:08:00
【问题描述】:

我正在使用 xlrd、xlwt、openpyxl 进行 excel 文件操作 我有下面的方法,它遍历文件夹中的 30 多个文件并更改文件中每一行的特定列(某些文件有 5、15、17 等行)

上面的方法可以反复运行,每个文件都会相应地更新。 但, 一旦我正在编辑文件(任何文件,并且编辑甚至可以是其中一个单元格中的微小变化(例如从 A 更改为 a),xlrd 就无法读取该文件,并且我在下面遇到异常. 知道为什么吗?

例外:

Traceback(最近一次调用最后一次):

文件“/home/ohad/automationProj/automation-linux/0_master_code_prep.py”,第 154 行,在

sanity_run_all_change()

文件“/home/ohad/automationProj/automation-linux/0_master_code_prep.py”,第 68 行,在 sanity_run_all_change 中

ExcelWorkBook1 = open_workbook(config.STDFOLDER + '%s.xlsx'%suitename, on_demand=True)

文件“/usr/local/lib/python2.7/dist-packages/xlrd/init.py”,第 422 行,在 open_workbook 中

ragged_rows=ragged_rows,

文件“/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py”,第 794 行,在 open_workbook_2007_xml 中

x12sheet.process_stream(zflo, 标题)

文件“/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py”,第 534 行,在 own_process_stream 中

self.do_dimension(elem)

文件“/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py”,第 568 行,在 do_dimension 中

rowx, colx = cell_name_to_rowx_colx(last_cell_ref)

文件“/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py”,第 91 行,在 cell_name_to_rowx_colx 中

断言 0

断言错误

代码:

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 xlrd


    【解决方案1】:

    在我的情况下,错误是,

    assert 1 <= nr <= self.utter_max_rows AssertionError
    

    在 Python 中的 .xls 文件中。

    访问此链接以查看我的答案并在sheet.py 中更改MAX-COLUMNS

    AssertionError with pandas when reading excel

    我想你的问题会解决的... :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多