-1

My objective is to take a large number of XLS files and convert them to XLSX. I can do it one line at a time with a simple operation, or do a large number of files in a batch if anyone knows a way.

I attempted to use most of the solutions on this Stack post, but it seems they no longer work, or apply. It is 9 years old, so a modern solution may be needed.

Code I tried:

p.save_book_as(file_name='C://Users//user1//Downloads//oldfile.xls',
           dest_file_name='C://Users//user1//Downloads//oldfile.xlsx')

But this resulted in an error:

 raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'<?xml ve'
user18139
  • 188
  • 1
  • 3
  • 13

1 Answers1

0

You could try Tablib, as in:

with open('input.xls', 'r') as input:
    data = Dataset().load(input)
    with open('output.xlsx', 'wb') as output:
        output.write(data.export('xlsx'))

Not sure if it supports your versions of xls/xlsx, though.

Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
  • It says for some reason "Dataset()" is not recognized. Is there an alternative solution? – user18139 May 10 '21 at 10:53
  • @user18139 What is the exact wording of the error? And what is "is", the library? I mean, where does the error come from? – Ecir Hana May 10 '21 at 11:52