簡體   English   中英

使用 openpyxl 打開.xlsm 文件時出現問題

[英]Issue while opening .xlsm file using openpyxl

我目前正在使用 openpyxl 將新工作表添加到.xlsm 文件中,使用 (read_only=False)

例如。

    wb = openpyxl.load_workbook("Input_file.xlsm", read_only=False, keep_vba=True)
    sheet = wb.create_sheet('Source_Data')
    final_row = dataframe_to_rows(final_df)
    #  code to add final row to sheet Source_Data
    wb.save("Input_file.xlsm")
    wb.close()


 Below is the error message

~\AppData\Local\Programs\Python\Python39\lib\zipfile.py in getinfo(self, name)
   1427         info = self.NameToInfo.get(name)
   1428         if info is None:
-> 1429             raise KeyError(
   1430                 'There is no item named %r in the archive' % name)
   1431 

KeyError: "There is no item named 'xl/drawings/NULL' in the archive"

我有同樣的問題。 我設法輕松解決了它(我不明白為什么,但它有效)。 顯然有一些圖像粘貼在一些隱藏的工作表中。

您需要找到並刪除它們。 (也許使它們可見也可以解決問題-我沒有檢查)有兩種方法可以做到。 Select 工作簿中的每個工作表。 然后:

選項1:按 F5 -> 特殊 -> 對象 這將突出顯示工作表上的所有隱藏圖像

選項2:轉到“主頁”選項卡->按“查找和選擇”->按“選擇窗格”您可以看到所有隱藏的圖像-並刪除它們

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM