因为待合并的EXCEL表格有密码,所以在pd.read_excel(xls, 'sheet_name')读取的时候会提示失败,想问下这个情况怎么解决?
安装msoffcrypto-tool:pip install msoffcrypto-tool
执行以下代码:
import msoffcrypto
import io
import pandas as pd
file = msoffcrypto.OfficeFile(open("encrypted.xlsx", "rb"))
file.load_key(password="Passw0rd") # Use password
decrypted = io.BytesIO()
file.decrypt(decrypted)
df = pd.read_excel(decrypted)
print(df)
3. 合并多个Excel表格:data = pd.concat([df0, df1, ...], axis=0)
如果我想打开的是一个文件夹下面的多个文件,请问一下这个代码:file = msoffcrypto.OfficeFile(open("encrypted.xlsx", "rb"))该如何修改一下,还有在合并的时候会提示 name 'df1' is not defined