Skip to content

BUG: how to convert .xls to .xlsx because Pandas failed to open .xls files #58470

Closed
@Chirawat3987

Description

@Chirawat3987

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

df = pd.read_excel('ZARR2001.xls')
df.to_excel('ZARR2001.xlsx')

Issue Description

The error that I get from pandas is:


ValueError Traceback (most recent call last)
Cell In[40], line 3
1 import pandas as pd
----> 3 df = pd.read_excel('ZARR2001.xls')
4 df.to_excel('ZARR2001.xlsx')

File /opt/conda/miniconda3/lib/python3.8/site-packages/pandas/util/_decorators.py:299, in deprecate_nonkeyword_arguments..decorate..wrapper(*args, **kwargs)
294 msg = (
295 f"Starting with Pandas version {version} all arguments of "
296 f"{func.name}{arguments} will be keyword-only"
297 )
298 warnings.warn(msg, FutureWarning, stacklevel=stacklevel)
--> 299 return func(*args, **kwargs)

File /opt/conda/miniconda3/lib/python3.8/site-packages/pandas/io/excel/_base.py:336, in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
334 if not isinstance(io, ExcelFile):
335 should_close = True
--> 336 io = ExcelFile(io, storage_options=storage_options, engine=engine)
337 elif engine and engine != io.engine:
338 raise ValueError(
339 "Engine should not be specified when passing "
340 "an ExcelFile - ExcelFile already has the engine set"
341 )

File /opt/conda/miniconda3/lib/python3.8/site-packages/pandas/io/excel/_base.py:1080, in ExcelFile.init(self, path_or_buffer, engine, storage_options)
1078 ext = "xls"
1079 else:
-> 1080 ext = inspect_excel_format(
1081 content=path_or_buffer, storage_options=storage_options
1082 )
1084 if ext == "ods":
1085 engine = "odf"

File /opt/conda/miniconda3/lib/python3.8/site-packages/pandas/io/excel/_base.py:974, in inspect_excel_format(path, content, storage_options)
972 return "xls"
973 elif not peek.startswith(ZIP_SIGNATURE):
--> 974 raise ValueError("File is not a recognized excel file")
976 # ZipFile typing is overly-strict
977 # python/typeshed#4212
978 zf = zipfile.ZipFile(stream) # type: ignore[arg-type]

ValueError: File is not a recognized excel file

Expected Behavior

pls help

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugClosing CandidateMay be closeable, needs more eyeballsIO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions