I have tried the following code to convert xls excel files to xlsx files using xlrd and openpyxl libraries in python since openpyxl does not read xls files.
import xlrd
import openpyxl
excel_files = ['one.xls', 'two.xls', 'three.xls', 'four.xls', 'five.xls', 'six.xls']
for excel_file in excel_files:
wb_old = xlrd.open_workbook(excel_file)
wb_new = openpyxl.Workbook()
ws_new = wb_new.active
for ws_old in wb_old.sheets():
for row in range(ws_old.nrows):
for col in range(ws_old.ncols):
ws_new.cell(row=row, column=col).value = ws_old.cell(row=row, column=col).value
wb_new.save(excel_file.replace('.xls', '.xlsx'))
The problem is that I get the following error: TypeError: cell() got an unexpected keyword argument 'row'. This error is in reference to this line of code: ws_new.cell(row=row, column=col).value = ws_old.cell(row=row, column=col).value
Can someone help me on how to fix this?
The line in your code
causes issues for two reasons;
(0, 0). This is the cause of the error message you see.row=andcolumn=in the Openpyxl cell being 0 will fail.You'd need to change that line to something like this;