简体   繁体   中英

openpyxl load_workbook ValueError: Table with name Table1 already exists

So I try to load an existing excel file with openpyxl using load_workbook and get the following error:

wb = load_workbook(filename)
  File "/home/barrachina/anaconda3/envs/tf-2-cpu/lib/python3.7/site-packages/openpyxl/reader/excel.py", line 315, in load_workbook
    reader.read()
  File "/home/barrachina/anaconda3/envs/tf-2-cpu/lib/python3.7/site-packages/openpyxl/reader/excel.py", line 280, in read
    self.read_worksheets()
  File "/home/barrachina/anaconda3/envs/tf-2-cpu/lib/python3.7/site-packages/openpyxl/reader/excel.py", line 251, in read_worksheets
    ws.add_table(table)
  File "/home/barrachina/anaconda3/envs/tf-2-cpu/lib/python3.7/site-packages/openpyxl/worksheet/worksheet.py", line 571, in add_table
    raise ValueError("Table with name {0} already exists".format(table.name))
ValueError: Table with name Table1 already exists

This happens with version 3.0.5 but didn't happen with 3.0.3 .

  1. How can I open it? I believe I should somehow open the file and delete one table definition (which according to the message I have at least two).
  2. (For developers): I don't like the error. Offer a solution would be better or just a warning. Microsoft Office and Open office do open the file...

Writer from open office opens it without a problem, however, MS Excel has the following message:

在此处输入图片说明

After opening the file with Excel, saving it and closing it, it started working. However, I would have liked a solution without having to use Excel. Furthermore, this document was fully generated with openpyxl 3.0.2 so it should have been prevented to create a Table with the same name twice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM