openpyxl excel 파일시스템으로 저장

2023. 11. 27. 20:05개발/openpyxl

728x90
반응형
  • excel 파일 읽은후 파일 시스템으로 저장
excel_file = load_workbook('temp.xlsx')


sheet1 = excel_file['시트이름']

row = 0  
for index, value in enumerate(data):  
    sheet1.cell(row, index+1,value)  


# excel 파일 bytesIO로 저장

with NamedTemporaryFile() as tmp:  
    excel_file.save(tmp)  
    tmp.seek(0)  
    stream = tmp.read()

# Set up the Http response.

filename = 'test.xlsx'  
response = HttpResponse(  
    stream,  
    content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'  
)  
response["Content-Disposition"] = "attachment; filename=%s" % filename # 한글 제목 설정  
return response  

'개발 > openpyxl' 카테고리의 다른 글

엑셀 파일 합치기: openpyxl로 쉽게 해결하기  (0) 2023.12.10