1

You need to convert xls to xlsx on the hosting without win32com. I tried this code:

import xlrd, os
from openpyxl.workbook import Workbook


def open_xls_as_xlsx(filename):
    # first open using xlrd
    book = xlrd.open_workbook( filename =filename)
    index = 0
    nrows, ncols = 0, 0
    while nrows * ncols == 0:
        sheet = book.sheet_by_index(index)
        nrows = sheet.nrows
        ncols = sheet.ncols
        index += 1

    # prepare a xlsx sheet
    book1 = Workbook()
    sheet1 = book1.active()

    for row in range(1, nrows):
        for col in range(1, ncols):
            sheet1.cell(row=row, column=col).value = sheet.cell_value(row, col)

    return book1


open_xls_as_xlsx(os.getcwd() + '/Расписание_1-4_курсов_с_01.04_по_05.07.2021_(2_поток).xls').save(filename = 'path_to_file.xlsx')

but got an error:

'Worksheet' object is not callable

Or can I do something else? Help please

  • Please [edit] your question and post the **full text** of the error and traceback. Do not post images of text. – MattDMo Aug 23 '21 at 18:32

1 Answers1

1

after active, there must not be a ().

 sheet1 = book1.active

Furthermore, there was a bug in the 2d for loop. xlrd starts coordinates at 0 while openpyxl starts them at 1.

    for row in range(0, nrows):
        for col in range(0, ncols):
            print(sheet.cell_value(row,col))
            sheet1.cell(row=row+1, column=col+1).value = sheet.cell_value(row, col)
Ohnemichel
  • 324
  • 2
  • 9