From password-protected Excel file to pandas DataFrame

前端 未结 4 891
青春惊慌失措
青春惊慌失措 2020-12-15 11:42

I can open a password-protected Excel file with this:

import sys
import win32com.client
xlApp = win32com.client.Dispatch(\"Excel.Application\")
print \"Excel         


        
4条回答
  •  北海茫月
    2020-12-15 11:55

    from David Hamann's site (all credits go to him) https://davidhamann.de/2018/02/21/read-password-protected-excel-files-into-pandas-dataframe/

    Use xlwings, opening the file will first launch the Excel application so you can enter the password.

    import pandas as pd
    import xlwings as xw
    
    PATH = '/Users/me/Desktop/xlwings_sample.xlsx'
    wb = xw.Book(PATH)
    sheet = wb.sheets['sample']
    
    df = sheet['A1:C4'].options(pd.DataFrame, index=False, header=True).value
    df
    

提交回复
热议问题