콘솔워크

[python] 암호화된 엑셀파일 읽기 함수 (dataframe으로 반환) 본문

프로그래밍/python

[python] 암호화된 엑셀파일 읽기 함수 (dataframe으로 반환)

콘솔워크 2022. 8. 12. 10:45
반응형

msoffcrypto-tool 라이브러리를 설치한다.

 pip install msoffcrypto-tool, pandas

 

improt 해주고 실시 df 가져오기

import msoffcrypto
import io
import pandas as pd


def get_df_from_password_excel(excelpath, password):
    df = pd.DataFrame()
    temp = io.BytesIO()
    with open(excelpath, 'rb') as f:
        excel = msoffcrypto.OfficeFile(f)
        excel.load_key(password)
        excel.decrypt(temp)
        df = pd.read_excel(temp)
        del temp
    return df

 

반응형