728x90
반응형
보안을 위해 데이터프레임을 엑셀 파일로 저장하고, 지정된 시간이 지나면 파일을 열지 못하도록 하려면 다음과 같은 코드를 사용할 수 있습니다. 이 기능은 엑셀 파일에 대한 암호 보호 등 보안 기능을 통해 구현될 수 있습니다.
import pandas as pd
from datetime import datetime, timedelta
# Create a sample dataframe
df = pd.DataFrame({'col1': [1, 2, 3, 4], 'col2': [10, 20, 30, 40]})
# Set the expiration date for the file
expiration_date = datetime.now() + timedelta(days=7)
# Save the dataframe to an excel file with password protection
writer = pd.ExcelWriter('df.xlsx', engine='openpyxl')
df.to_excel(writer, index=False)
writer.save()
# Add password protection to the excel file
book = writer.book
sheet = writer.sheets['Sheet1']
sheet.protection.set_password('password')
# Add a custom property to the file with the expiration date
book.custom_properties = {'Expiration Date': expiration_date.strftime('%Y-%m-%d %H:%M:%S')}
book.save('df.xlsx')
엑셀 파일을 열려는 경우에는 기본 암호 보호 기능을 통해 파일의 암호를 확인하고, 그 외에도 애플리케이션에서 Expiration Date 프로퍼티를 조회하여 현재 시각과 비교하여 파일이 만료되었는지 확인할 수 있습니다.
728x90
반응형
'파이썬' 카테고리의 다른 글
데이터프레임 특정값을 Nan으로 변경하기 (0) | 2023.02.09 |
---|---|
PDF 문서에서 테이블을 추출하여 판다 데이터 프레임으로 변환 (0) | 2023.02.09 |
파이썬을 이용해서 부동산 관련 문서를 정리하는 코드의 예제 (0) | 2023.02.09 |
파이썬에서 엑셀로 저장할 때 보기좋게 정리하는 코드 (0) | 2023.02.09 |
파이썬으로 부동산고객관리 시스템 코드 (0) | 2023.02.09 |