如何在python中读取具有宏'xlsm'格式的受密码保护的Excel文件。我知道密码。尝试使用openpyxl和其他几种方式打开,如下所示:
''' both of these are giving ImportError for pythoncom dlls'''
import win32com
def Remove_password_xlsx(filename, pw_str):
xcl = win32com.client.Dispatch("Excel.Application")
wb = xcl.Workbooks.Open(filename, False, False, None, pw_str)
xcl.DisplayAlerts = False
wb.SaveAs(filename, None, '', '')
xcl.Quit()
Remove_password_xlsx(file, 'pwd')
'''---------------'''
import pandas as pd
import xlwings as xw
PATH = 'file.xlsm'
wb = xw.Book(PATH)
sheet = wb.sheets['sheet1']
df = sheet['A1:C4'].options(pd.DataFrame, index=False, header=True).value
df