2

Im using xlrd,xlwt,openpyxl for excel file manipulation i have the method below, which goes over 30 files in folder and change specific column for each row in file (some file has 5,15,17,etc rows)

The method above can be run over and over and each file will be updated accordingly. But, Once i'm editing file (any of the files, and editing can be even small change in one of the cells (change from A to a for instance), the file cant be read by xlrd, and i'm getting the exception below. Any idea why?

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

Code:

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)
Community
  • 1
  • 1
OhadS
  • 21
  • 3

1 Answers1

1

In my case the error was,

assert 1 <= nr <= self.utter_max_rows AssertionError

in .xls file in Python.

Visit this link to see my answer and do change in sheet.py for MAX-COLUMNS.

AssertionError with pandas when reading excel

I think you problem will be solved... :)

anothernode
  • 5,100
  • 13
  • 43
  • 62