ASG
ASG

Reputation: 51

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)

Upvotes: 2

Views: 7738

Answers (2)

ASG
ASG

Reputation: 51

Just including my finished code for future use by others which uses pandas - worked almost instantly

import os import pandas as pd

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

for filename in os.listdir(directory):

    if filename.endswith(".xls"):
        df = pd.read_excel(filename)
        df.to_excel(filename + ".xlsx")

Upvotes: 0

sepideh_ssh
sepideh_ssh

Reputation: 198

use pandas

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

Upvotes: 0

Related Questions