Search code examples
pythonexcelfile-conversion

Converting xls files to xlsx using python


I've got loads of 97-2003 Excel xls files i wanna bulk convert to xlsx.

I found the xls2xlsx documentation but can't seem to get it to work.

I have tried googling the errors and searching but to no avail.

import os

from xls2xlsx import XLS2XLSX


directory = 'C:\\Users\\Python Scripts\\convertXLStoXLSX\\'

for filename in os.listdir(directory):

    if filename.endswith(".xls"):
        x2x = XLS2XLSX(filename)
        x2x.to_xlsx(filename)
    else:
        continue

I am getting the error message:

ImportError: cannot import name 'GuessedAtParserWarning' from 'bs4' (C:\Users\wf5931\AppData\Local\Continuum\anaconda3\lib\site-packages\bs4\__init__.py)

Solution

  • use pandas

    import pandas as pd
    df = pd.read_excel("file.xls")
    df.to_excel("file.xlsx")