【问题标题】:Error while reading xlsm file by Pandas : "Conditional Formatting extension is not supported"Pandas 读取 xlsm 文件时出错:“不支持条件格式扩展名”
【发布时间】:2023-01-21 01:18:17
【问题描述】:

我想通过 Pandas 读取一个 xlsm 文件:

pd.read_excel("data.xlsm", engine='openpyxl', sheet_name="sheet1")

但是,我收到错误:

C:\Users\anaconda3\lib\site-packages\openpyxl\worksheet\_read_only.py:79: UserWarning: Unknown extension is not supported and will be removed
  for idx, row in parser.parse():
C:\Users\anaconda3\lib\site-packages\openpyxl\worksheet\_read_only.py:79: UserWarning: Conditional Formatting extension is not supported and will be removed
  for idx, row in parser.parse():

另一种尝试:我以 xlsx 格式保存数据文件并尝试通过以下方式读取:

pd.read_excel("data.xlsx", engine='openpyxl', sheet_name="sheet1")

而这一次,我收到以下错误:

  File "C:\Users\AppData\Local\Temp\ipykernel_28028\1689108907.py", line 1, in <module>
    data = pd.read_excel(data_original_filepath, engine='openpyxl', sheet_name=sheet_name)

  File "C:\Users\anaconda3\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)

  File "C:\Users\anaconda3\lib\site-packages\pandas\io\excel\_base.py", line 457, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)

  File "C:\Users\anaconda3\lib\site-packages\pandas\io\excel\_base.py", line 1419, in __init__
    self._reader = self._engines[engine](self._io, storage_options=storage_options)

  File "C:\Users\anaconda3\lib\site-packages\pandas\io\excel\_openpyxl.py", line 525, in __init__
    super().__init__(filepath_or_buffer, storage_options=storage_options)

  File "C:\Users\anaconda3\lib\site-packages\pandas\io\excel\_base.py", line 518, in __init__
    self.book = self.load_workbook(self.handles.handle)

  File "C:\Users\anaconda3\lib\site-packages\pandas\io\excel\_openpyxl.py", line 536, in load_workbook
    return load_workbook(

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\reader\excel.py", line 317, in load_workbook
    reader.read()

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\reader\excel.py", line 278, in read
    self.read_workbook()

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\reader\excel.py", line 150, in read_workbook
    self.parser.parse()

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\reader\workbook.py", line 49, in parse
    package = WorkbookPackage.from_tree(node)

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py", line 83, in from_tree
    obj = desc.from_tree(el)

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py", line 85, in from_tree
    return [self.expected_type.from_tree(el) for el in node]

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py", line 85, in <listcomp>
    return [self.expected_type.from_tree(el) for el in node]

  File "C:\Users\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
    return cls(**attrib)

TypeError: __init__() missing 1 required positional argument: 'id'

知道如何解决这个问题吗?

实际上,我必须读取 xlsm 文件。将格式更改为 xlsx 仅用于试用目的。

【问题讨论】:

    标签: python pandas xlsx readfile xlsm


    【解决方案1】:

    请尝试此代码块。

    import openpyxl
    file='data.xlsm'
    wb=openpyxl.load_workbook(file, data_only=True, read_only=False, keep_vba=True)
    
    

    【讨论】:

    • 谢谢。但是,对于 xlsx 和 xlsm 文件,我得到了相同的错误。你知道我收到这个错误的原因吗?数据集本身有什么问题吗?
    【解决方案2】:

    openpyxl web page 安装最新的 openpyxl

    如果您指定 sheet_name 它正在工作

    pd.read_excel("data.xlsm", sheet_name="sheet1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多