Project 30

Xlsxwriter 엑셀 export 기능 구현

xlwt 모듈로 excel export 기능을 구현하려고 했으나 xlsx 확장자가 안되기에 업무용으로 엑셀을 export해서 주고 받기에는 문제가 있어보였음 그래서 급하게 다른 모듈을 찾다가 xlsxwriter 모듈을 사용하게 됨 openpyxl과 xlsxwriter 중 고민했지만 비슷한것 같아 속도가 더 빠른 xlsxwriter 모듈을 선택함 (나는 간단한 파일 작성이여서 사실 속도 차이는 못느낄 듯) 앞으로 절대 xlwt 모듈은 사용안하는 것을 권장함😥 그리고 결정적으로 xlwt 모듈을 행의 height 설정이 불가했음(설정 방법 못 찾음) 👉 xls 확장자는 2003년 이하 버전 확장자인데 xlsx 확장자 선택이 불가함 Xlsxwriter 모듈 설치 # pip 설치 > pip install Xlsx..

xlwt excel 스타일 설정

🚫xlwt 구현 방법 참고용 (권장X) 이유는 👉 https://carpet-part1.tistory.com/470 참고🚫 excel 스타일 설정하기 views.py excel_export 전체 코드 import xlwt def excel_export(request): locale.setlocale(locale.LC_ALL,'') today = datetime.today().strftime('%Y-%m-%d') todayValue = datetime.today().strftime('%Y-%m-%d (%a)') response = HttpResponse(content_type="application/vnd.ms-excel") response["Content-Disposition"] = 'attachment..

Django Filters (objects filter)

objects를 가져올때 filter 설정하는 방법 1️⃣ 필터없이 모델의 데이터 가져오기 objects.all() 모델에 설정해놓은 이름으로 가져올 수 있음 values_list() 안에 모델에 설정한 이름으로 데이터 전체 가져올 수 있음 rows = Board.objects.all().values_list('start_date', 'company', 'position', 'guest_name') 2️⃣ 조건을 설정해서 원하는 조건의 데이터만 가져오고 싶을 때 objects.filter()를 통해 조건을 설정할 수 있음 아래의 조건은 시작일(start_date)

Django excel export 구현 순서(xlwt)

🚫xlwt 구현 방법 참고용 (권장X) 이유는 👉 https://carpet-part1.tistory.com/470 참고🚫 1️⃣ xlwt 받기 pip install xlwt 2️⃣ 엑셀 다운로드 구현 엑셀 export 기능을 구현할 app의 views.py import xlwt def excel_export(request): response = HttpResponse(content_type="application/vnd.ms-excel") response["Content-Disposition"] = 'attachment;filename*=UTF-8\'\'example.xls' wb = xlwt.Workbook(encoding='ansi') #encoding은 ansi로 해준다. ws = wb.add_s..

Python excel export(XlsxWriter)

python excel export 하는방법 이후 xlwt모듈 사용법을 게시할 것이지만 이 모듈을 먼저 소개하는 이유는 내가 xlwt 모듈을 잘 모르고 사용했다가 크게 후회를 했기 때문😥 XlsxWriter 사용방법과 자세한 이야기는 이후 게시글 참고 👉 https://carpet-part1.tistory.com/470 ✅ XlsxWriter를 설치 pip install XlsxWriter * XlsxWriter : 엑셀파일 처리 및 사용하기 위한 라이브러리 from pandas import DataFrame import xlsxwriter def export_date_excel(request): header = [ 'A','B','C'] dataF = DataFrame(detail_list,column..

템플릿 날짜 포맷 설정 및 날짜로 원하는 결과 가져오기

날짜 포맷 템플릿에서 날짜를 원하는 형식으로 가져오고 싶을때 👇 {{ board.start_date|date:'Y.m.d (D)' }} 날짜로 원하는 결과 가져오기 시작일이 현재 날짜보다 크거나 같고 종료일이 작거나 같은 경우만 불러오기 {% if board.start_date|date:'Ymd' = time|date:'Ymd' %} board_list.html 기간 업체명 직책 이름 {% for board in boards %} {% if board.start_date|date:'Ymd' = time|date:'Ymd' %} {{ board.start_date|date:'Y.m.d (D)' }} ~ {{ board.end_date|date:'Y.m.d (D)' }} {{ board.company }} ..