获取'keyError:“在试图打开Excel

问题描述 投票:0回答:1
当我查看XL文件夹中XLSX文件的存档时,没有文件共享string.xml.

,因为Excel中没有字符串。该文件在Excel中正确打开,没有任何问题,但没有使用Python。 import openpyxl import pandas import xlrd import os globaltrackerdf = pandas.read_excel (r'C:\Users\Documents\Trackers\Tracker-Global Tracker_V2-2022-06-13.xlsx',sheet_name="Sheet1",engine="openpyxl")

对我有用的解决方案:使用您的Excel重新放置您的文件。我的文件也可以在Excel中打开罚款,但是在将文件拉开并在其中看着没有sharedStrings.xml

。似乎有一个错误,其中保存XLSX可能不会产生
sharedStrings.xml
文件。我发现了为什么会发生这种情况的各种想法,但是由于我无法访问客户的Excel,不确定是什么原因造成的。
python excel pandas dataframe powerbi
1个回答
1
投票
https://www.adimian.com/blog/fast--xlsx-parsing-with-python/

    
您可以使用XLWINGS来解决这个问题。
def open_and_close_excel_file(app,filepath): try: workbook = app.books.open(filepath) workbook.save() workbook.close() except Exception as e: print(f"Error opening or closing Excel file: {e}") app = xw.App(visible=False) directory = input('enter the path:\n') for root,_,files in os.walk(directory): try: for file in files: full_path = os.path.join(root,file) print(full_path) open_and_close_excel_file(app, full_path) finally: app.quit()

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.